package io.renren.socket;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.renren.common.utils.Constant;
import io.renren.common.utils.StringUtils;
import io.renren.modules.substation.entity.*;
import io.renren.modules.substation.service.*;
import org.apache.commons.lang.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.*;
import java.math.BigInteger;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.*;


@Component
public class ServerHandler extends Middleware {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    protected TInfoDevInfoService tInfoDevInfoService;
    @Autowired
    protected TJsonInfoService tJsonInfoService;
    @Autowired
    protected TRegisterPointInfoService tRegisterPointInfoService;
//    @Autowired
//    protected TPpInfoService tPpInfoService;
    @Autowired
    protected TPpRegInfoService tPpRegInfoService;
    @Autowired
    protected TPointInfoDataConfService tPointInfoDataConfService;

    @Autowired
    protected TInfoEfencePointService tInfoEfencePointService;

    @Autowired
    protected TSampBasiDataInfoService tSampBasiDataInfoService;
    @Autowired
    protected TSampCameraDataInfoService tSampCameraDataInfoService;
    @Autowired
    protected TSampDevDataInfoService tSampDevDataInfoService;
    @Autowired
    protected TSampIrDataInfoService tSampIrDataInfoService;
    @Autowired
    protected TSampIrSensorTempService tSampIrSensorTempService;
    @Autowired
    protected TSampJfDataInfoService tSampJfDataInfoService;
    @Autowired
    protected TSampThDataInfoService tSampThDataInfoService;
    @Autowired
    protected TSampBasiDataInfoHisService tSampBasiDataInfoHisService;
    @Autowired
    protected TSampCameraDataInfoHisService tSampCameraDataInfoHisService;
    @Autowired
    protected TSampDevDataInfoHisService tSampDevDataInfoHisService;
    @Autowired
    protected TSampIrDataInfoHisService tSampIrDataInfoHisService;
    @Autowired
    protected TSampIrSensorTempHisService tSampIrSensorTempHisService;
    @Autowired
    protected TSampJfDataInfoHisService tSampJfDataInfoHisService;
    @Autowired
    protected TSampThDataInfoHisService tSampThDataInfoHisService;

    @Autowired
    protected TFileInfoService tFileInfoService;
    @Autowired
    protected TFileLogInfoService tFileLogInfoService;
    @Autowired
    protected TInfoDevRoutineParamService tInfoDevRoutineParamService;

    @Autowired
    protected TBusiDevStatusInfoService tBusiDevStatusInfoService;
    @Autowired
    protected TBusiDevMonitorHisService tBusiDevMonitorHisService;
    @Autowired
    protected TBusiDevMonitorInfoService tBusiDevMonitorInfoService;

    @Autowired
    protected TInfoAlarmConfigService tInfoAlarmConfigService;

    @Autowired
    protected TBaseDictInfoService tBaseDictInfoService;

    @Autowired
    protected TBusiSysAlarmInfoService tBusiSysAlarmInfoService;
    @Autowired
    protected TBusiSysEventInfoService tBusiSysEventInfoService;

    @Autowired
    protected TInfoVariableInfoService tInfoVariableInfoService;


    @Autowired
    protected TSampAeDataInfoService tSampAeDataInfoService;
    @Autowired
    protected TSampAeDataInfoHisService tSampAeDataInfoHisService;
    @Autowired
    protected TSampNoiseBaseInfoService tSampNoiseBaseInfoService;
    @Autowired
    protected TSampNoiseBaseInfoHisService tSampNoiseBaseInfoHisService;
    @Autowired
    protected TSampSoundInfoService tSampSoundInfoService;
    @Autowired
    protected TSampSoundInfoHisService tSampSoundInfoHisService;
    @Autowired
    protected TSampTevDataInfoService tSampTevDataInfoService;
    @Autowired
    protected TSampTevDataInfoHisService tSampTevDataInfoHisService;
    @Autowired
    protected TFileInfoHisService tFileInfoHisService;

    private static ServerHandler serverHandler;

    @PostConstruct //通过@PostConstruct实现初始化bean之前进行的操作
    public void init() {
        serverHandler = this;
        serverHandler.tSampAeDataInfoService = this.tSampAeDataInfoService;
        serverHandler.tSampAeDataInfoHisService = this.tSampAeDataInfoHisService;
        serverHandler.tSampNoiseBaseInfoService = this.tSampNoiseBaseInfoService;
        serverHandler.tSampNoiseBaseInfoHisService = this.tSampNoiseBaseInfoHisService;
        serverHandler.tSampSoundInfoService = this.tSampSoundInfoService;
        serverHandler.tSampSoundInfoHisService = this.tSampSoundInfoHisService;
        serverHandler.tSampTevDataInfoService = this.tSampTevDataInfoService;
        serverHandler.tSampTevDataInfoHisService = this.tSampTevDataInfoHisService;

        serverHandler.tInfoAlarmConfigService = this.tInfoAlarmConfigService;
        serverHandler.tBusiSysEventInfoService = this.tBusiSysEventInfoService;
        serverHandler.tInfoVariableInfoService = this.tInfoVariableInfoService;

        serverHandler.tInfoDevInfoService = this.tInfoDevInfoService;
        serverHandler.tJsonInfoService = this.tJsonInfoService;
        serverHandler.tRegisterPointInfoService = this.tRegisterPointInfoService;
//        serverHandler.tPpInfoService = this.tPpInfoService;
        serverHandler.tPpRegInfoService = this.tPpRegInfoService;
        serverHandler.tPointInfoDataConfService = this.tPointInfoDataConfService;
        serverHandler.tInfoEfencePointService = this.tInfoEfencePointService;

        serverHandler.tSampBasiDataInfoService = this.tSampBasiDataInfoService;
        serverHandler.tSampCameraDataInfoService = this.tSampCameraDataInfoService;
        serverHandler.tSampDevDataInfoService = this.tSampDevDataInfoService;
        serverHandler.tSampIrDataInfoService = this.tSampIrDataInfoService;
        serverHandler.tSampIrSensorTempService = this.tSampIrSensorTempService;
        serverHandler.tSampJfDataInfoService = this.tSampJfDataInfoService;
        serverHandler.tSampThDataInfoService = this.tSampThDataInfoService;
        serverHandler.tSampBasiDataInfoHisService = this.tSampBasiDataInfoHisService;
        serverHandler.tSampCameraDataInfoHisService = this.tSampCameraDataInfoHisService;
        serverHandler.tSampDevDataInfoHisService = this.tSampDevDataInfoHisService;
        serverHandler.tSampIrDataInfoHisService = this.tSampIrDataInfoHisService;
        serverHandler.tSampIrSensorTempHisService = this.tSampIrSensorTempHisService;
        serverHandler.tSampJfDataInfoHisService = this.tSampJfDataInfoHisService;
        serverHandler.tSampThDataInfoHisService = this.tSampThDataInfoHisService;

        serverHandler.tBusiDevStatusInfoService = this.tBusiDevStatusInfoService;
        serverHandler.tBusiDevMonitorInfoService = this.tBusiDevMonitorInfoService;
        serverHandler.tBusiDevMonitorHisService = this.tBusiDevMonitorHisService;
        serverHandler.tInfoAlarmConfigService = this.tInfoAlarmConfigService;
        // 初使化时将已静态化的testService实例化
    }

    public ServerHandler() {
        super("server");
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void handlerData(ChannelHandlerContext ctx, Object msg) {
        // TODO Auto-generated method stub
        try {
//            logger.debug("obj msg:" + msg);
//            logger.info("8181端口server接收数据:" +  msg.toString());
            String revHexMsg = msg.toString();
//            String revHexMsg = new String(req, "UTF-8");
            if (revHexMsg.length() < 20) {
                logger.error("接收到的数据长度不足！");
            }
            if (!revHexMsg.substring(0, 8).equals("FFFFFFFF")) {
                logger.error("消息识别码错误！:" + revHexMsg);
                return;
            }
            String hexLen = revHexMsg.substring(8, 16);
            //解析长度
            BigInteger hexLen2 = new BigInteger(hexLen, 16);
            hexLen2 = hexLen2.multiply(new BigInteger("2"));
//            String revMsg = StringUtils.hexStringToString(revHexMsg.substring(16));
            int datalen = revHexMsg.substring(16).length();
            //计算长度
            BigInteger datalen2 = new BigInteger(String.valueOf(datalen));
//            ctx.channel().writeAndFlush(msg.toString());
//            logger.debug("转码前:" + revHexMsg.substring(16));
            byte[] req = StringUtils.hexStringToByteArray(revHexMsg.substring(16));
            //json转utf-8中文
            String revMsg = new String(req, "UTF-8");
//            logger.debug("转码后:" + revMsg);
            if (hexLen2.compareTo(datalen2) != 0) {
                logger.error("解析长度不匹配: encodeLen(" + hexLen2 + ") datalen(" + datalen2 + ")");
                return;
            }
            JSONObject obj = (JSONObject) JSONObject.parse(revMsg);
            logger.debug("obj size[" + obj.size() + "]revMsg->obj:" + obj);
            if (obj.size() < 1) {
                logger.warn("收到不可解析的数据，不执行" + obj);
                return;
            }
            //业务处理

            dealMeteMsg(obj, ctx);
//            logger.debug("revHexMsg数据： " + revHexMsg);
        } catch (Exception ex) {
            logger.error("接收到的消息无法转换成JSON，错误信息：" + ex.getMessage());
        }
    }

    @Override
    protected void handlerReaderIdle(ChannelHandlerContext ctx) {
        // TODO Auto-generated method stub
        super.handlerReaderIdle(ctx);
        logger.warn(" ---- client " + ctx.channel().remoteAddress().toString() + " reader timeOut, --- close it");

        ctx.close();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
            throws Exception {
        logger.warn(name + "  exception" + cause.toString());
    }

    private void dealMeteMsg(JSONObject obj, ChannelHandlerContext ctx) {
        int iLen = 6;
        try {
            //处理解析后业务
            logger.debug("处理解析后业务dealMeteMsg");
//            String stationaddress = obj.getString("从站地址");
            byte amType = obj.getByte("协议类型");
            logger.debug("111");
            savejsontodb(obj);
            if (amType == Constant.AM_IEC104) {
//                byte flagType = obj.getByte("类型标识");
//                byte informationnum = obj.getByte("信息数量");
//                JSONObject whyobj = obj.getJSONObject("传送原因");
//                byte publicaddress = obj.getByte("公共地址");
//                JSONArray informationarray = obj.getJSONArray("信息体");
//                logger.debug("信息体:" + informationarray);
//                JSONObject absolutetimescale = obj.getJSONObject("绝对时标");
                logger.debug("decodeiec104json +");
                DecodeIEC104JSON.decodeiec104json(serverHandler, obj, ctx);
                logger.debug("decodeiec104json -");
            } else if (amType == Constant.AM_PRIVAT) {
//                JSONObject privateaminformation = obj.getJSONObject("私有协议信息");
//                logger.debug("私有协议信息:" + privateaminformation);
                logger.debug("decodeiecprivajson +");
                decodeiecprivajson(obj, ctx);
                logger.debug("decodeiecprivajson -");
            }

        } catch (Exception ex2) {
            logger.error("dealMeteMsg error： " + ex2);
            logger.error(ex2.getMessage(), ex2);
        }
    }

    private void savejsontodb(JSONObject obj) {

        try {
//            logger.debug("json长度:" + obj.toJSONString().length());
            if (obj.toJSONString().length() > 1024 * 10) {

            }
            String stationaddress = obj.getString("从站地址");
            byte amType = obj.getByte("协议类型");
            TJsonInfoEntity tJsonInfoEntity = new TJsonInfoEntity();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            String date = df.format(new Date());// new Date()为获取当前系统时间，也可使用当前时间戳
//            tJsonInfoEntity.setId(null);
            tJsonInfoEntity.setAddrIp(stationaddress);
            logger.debug("savejsontodb1");
            tJsonInfoEntity.setProtocolType(amType);
            tJsonInfoEntity.setJsonData(obj.toJSONString());
            tJsonInfoEntity.setCreateOpr(Long.valueOf("0"));
            tJsonInfoEntity.setLastOpr(Long.valueOf("0"));
            logger.debug("savejsontodb1");
            tJsonInfoEntity.setLastTime(date);
            tJsonInfoEntity.setCreateTime(date);
            logger.debug("" + tJsonInfoEntity);
            if (tJsonInfoEntity != null && stationaddress != null) {
                logger.debug("save");
//                ValidatorUtils.validateEntity(tJsonInfoEntity, AddGroup.class);
                serverHandler.tJsonInfoService.saveTJsonInfoEntity(tJsonInfoEntity);
            } else {
                logger.error("tJsonInfoEntity 或 IP null");
            }
            logger.debug("savejsontodb1");
        } catch (Exception e) {
            logger.error("savejsontodb error： " + e);
        }
    }

    //私有协议解析
    private void decodeiecprivajson(JSONObject obj, ChannelHandlerContext ctx) {
        try {
            String stationaddress = obj.getString("从站地址");
            JSONObject privateaminformation = obj.getJSONObject("私有协议消息");
//            logger.debug("私有协议消息:" + privateaminformation);

            String sessionid = privateaminformation.getString("会话编号");
            String messagedata = privateaminformation.getString("消息内容");
            JSONObject messagedataJson = (JSONObject) JSONObject.parse(messagedata);

            decodemessagedata(obj, messagedataJson, ctx);
        } catch (Exception ex) {
            logger.error("decodeiecprivajson error： " + ex);
        }
    }

    public static String numToHex16(int b) {
        return String.format("%04x", b);
    }

    private void sendJsonResMsgOKorERROR(String action, String OKorERROR, String msgcontent, JSONObject obj, String strkey, JSONObject conobj, ChannelHandlerContext ctx) {
        if (action == null || action.equals("")) {
            logger.error("sendJsonResMsgOKorERROR action=null");
            return;
        }
        try {
            JSONObject objRsp = new JSONObject();
            byte am = obj.getByte("协议类型");
            logger.debug("协议类型:"+am);
            logger.debug("从站地址:"+obj.getString("从站地址"));
            logger.debug("从站编码:"+obj.getString("从站编码"));
            objRsp.put("从站编码", obj.getString("从站编码"));//IP地址
            objRsp.put("从站地址", obj.getString("从站地址"));//IP地址
            objRsp.put("协议类型", am);//0x00—104协议，0x01—私有协议

            if (am == Constant.AM_IEC104) {
                objRsp.put("类型标识", Constant.M_SP_NA_1);
                objRsp.put("信息对象地址", Constant.M_SP_NA_1);//只有类型标志为136才是数组
                objRsp.put("遥控类型", Constant.M_SP_NA_1);
                objRsp.put("输出⽅式", Constant.M_SP_NA_1);
                objRsp.put("设置值", (byte) Constant.M_SP_NA_1);//只有类型标志为136才是数组
            } else if (am == Constant.AM_PRIVAT) {
                JSONObject uploadFileRspobj = new JSONObject();
                uploadFileRspobj.put(Constant.CMD_ACTION, action);
                uploadFileRspobj.put(Constant.CMD_MSGID, obj.getString("msgId"));
                uploadFileRspobj.put(Constant.CMD_RESULT, OKorERROR);
                if (OKorERROR.equals(Constant.CMD_OK)) {
                    if (msgcontent != null && !msgcontent.equals("")) {
                        uploadFileRspobj.put(Constant.CMD_MSG, msgcontent);
                    } else {
                        uploadFileRspobj.put(Constant.CMD_MSG, Constant.CMD_SUCCESS);
                    }
                } else {
                    if (msgcontent != null && !msgcontent.equals("")) {
                        uploadFileRspobj.put(Constant.CMD_MSG, msgcontent);
                    } else {
                        uploadFileRspobj.put(Constant.CMD_MSG, Constant.CMD_ERROR);
                    }
                }

                if (strkey != null && conobj != null) {
                    uploadFileRspobj.put(strkey, conobj);
                }

                JSONObject privateaminformation = obj.getJSONObject("私有协议消息");
                String sessionid = privateaminformation.getString("会话编号");
                logger.debug("私有协议消息:" + privateaminformation + " 会话编号:" + sessionid.trim());

                JSONObject obj2 = new JSONObject();//只有私有协议才有该字段
                obj2.put("会话编号", sessionid.trim());//会话ID，data区数据所属终端SN号
                obj2.put("消息内容", uploadFileRspobj);//私有协议消息数据，DATA内容
//                        array.add(obj2);
                objRsp.put("私有协议消息", obj2);//只有私有协议才有该字段
            }
            sendJsonResMsg(objRsp, ctx);

        } catch (Exception e) {
            logger.error("sendJsonResMsgOKorERROR error： " + e);
        }
    }

    private void sendJsonResMsg(JSONObject obj, ChannelHandlerContext ctx) {

        try {
//            String msg = JSONObject.toJSONString(obj);
            String objStr = obj.toJSONString();
            logger.debug("s-应答jsonStr:" + objStr);
//            String escstr = StringEscapeUtils.unescapeJava(objStr);
//            logger.debug("s-应答escstr:" + escstr);
            String Unistr = StringUtils.decodeUnicode(objStr);
            logger.debug("s-应答Unistr:" + Unistr);
            String unstr = StringUtils.convertUnicodeToCh(objStr);
            logger.debug("s-应答unstr:" + unstr);
            String msgstrH = StringUtils.toChineseHex(objStr);
            String jsonSize = String.format("%08X", msgstrH.length() / 2);
            String header = "FFFFFFFF" + jsonSize;
            logger.debug("s-header + msgstrH:" + header + msgstrH);
            ctx.channel().writeAndFlush(header + msgstrH);
        } catch (Exception e) {
            logger.error("s-sendJsonResMsg error： " + e);
        }
    }

    @Override
    // 向client发送消息
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
//        logger.debug("开始写数据");
//        byte [] by={(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,00,(byte) 0x0A,(byte) 0xC5,(byte) 0xFE};
//        ByteBuf encoded = ctx.alloc().buffer(by.length);
//        encoded.writeBytes(by);
        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            logger.debug("本机IP：" + ip);
        } catch (Exception ex) {
            logger.error("获取本机IP失败");
        }
//        ctx.write(encoded);
//        ctx.flush();
        String uuid = ctx.channel().id().asLongText();
        GatewayService.addGatewayChannel(uuid, ctx);
        logger.info("有新的链接进来: " + uuid);
        logger.info("新的链接ip: " + ctx.channel().remoteAddress() + "["+ctx.channel().localAddress()+"]");
        boolean close = false;
        String ipPort = ctx.channel().remoteAddress().toString();
        String IP = ipPort.substring(1,ipPort.indexOf(":"));
        logger.debug("链接IP:"+IP);
        String client="127.0.0.126";
        try {
            Properties properties = new Properties();
            // 使用InPutStream流读取properties文件
            BufferedReader bufferedReader = new BufferedReader(new FileReader("IPconfig.properties"));
            if (bufferedReader != null) {
                // 获取key对应的value值
                properties.load(bufferedReader);
                logger.debug("properties size:"+properties.size());
                client = properties.getProperty("CLIENT");
                if (client != null) {
                    logger.debug("client：" + client);
                } else {
                    logger.debug("client 配置为空 拒绝所有链接");
                    ctx.channel().close();
                }
            } else {
                logger.debug("client 配置为空 拒绝所有链接2");
                ctx.channel().close();
            }
        }catch (Exception e){
            logger.debug("配置文件[IPconfig.properties]异常 拒绝所有链接");
            ctx.channel().close();
        }

        if(ipPort.substring(1,ipPort.indexOf(":")).equals(client) || client.equals("0")) {
            close = false;
            logger.debug("合法地址：" + IP);
        }else{
            close = true;
        }
        if (close) {
            ctx.channel().close();
            logger.debug("非法地址拒绝链接：" + IP);
        }
    }

    private void decodemessagedata(JSONObject q_obj, JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("decodemessagedata");
        try {
            String action = obj.getString("action");
            String msgId = obj.getString("msgId");
            logger.debug("消息打印action：" + action + " " + msgId);
            String result = obj.getString("result");
            String msg = obj.getString("msg");
            logger.debug("结果打印：" + result + " " + msg);
//            终端响应（常规响应）示例：
//            {
//                "action":"setDevDataRsp",
//                    "msgId":"",
//                    "result":"ok",
//                    "msg":"授时成功"
//            }
//            或者
//            {
//                "action":"setDevDataRsp",
//                    "msgId":"",
//                    "result":"error",
//                    "msg":"授时失败"
//            }
//            注意：
//            响应端的 action 字段值，由对应的请求 action+Rsp 组成。如本例：
//            请求 action： setDevData
//            响应 action： setDevDataRsp
//            后续常规响应不再重复，参考此处即可。
            switch (action) {
//
                case "setDevDataRsp"://授时响应
                    setDevDataRsp(obj, ctx);
                    break;
                case "requestSyncTime"://终端主动授时请求
                    requestSyncTime(q_obj, obj, ctx);
                    break;
                case "setDevStateRsp"://修改终端状态响应
                    setDevStateRsp(obj, ctx);
                    break;
                case "setDevPermissionRsp"://设置终端权限
                    setDevPermissionRsp(obj, ctx);
                    break;
                case "setCycleRebootTimeRsp"://设置循环重启时间
                    setCycleRebootTimeRsp(obj, ctx);
                    break;
                case "getDevInfoRsp"://获取终端信息
                    getDevInfoRsp(obj, ctx);
                    break;
                case "setIrOverlayRsp"://设置红外融合参数
                    setIrOverlayRsp(obj, ctx);
                    break;
                case "setIrWarningRsp"://设置红外报警（监测区域）参数
                    setIrWarningRsp(obj, ctx);
                    break;
                case "setDevParamRsp"://设置终端常规参数
                    setDevParamRsp(obj, ctx);
                    break;
                case "getDevParamRsp"://查询终端常规参数
                    getDevParamRsp(obj, ctx);
                    break;
                case "setJfWarningRsp"://设置局放报警参数
                    setJfWarningRsp(obj, ctx);
                    break;
                case "getJfWarningRsp"://查询局放报警参数
                    getJfWarningRsp(obj, ctx);
                    break;
                case "setJfNoiseBaseRsp"://重置特高频局放底噪
                    setJfNoiseBaseRsp(obj, ctx);
                    break;
                case "getJfNoiseBaseRsp"://查询特高频局放底噪
                    getJfNoiseBaseRsp(obj, ctx);
                    break;
                case "setCamWarningRsp"://设置可见光报警参数
                    setCamWarningRsp(obj, ctx);
                    break;
                case "getCamWarningRsp"://查询可见光报警参数
                    getCamWarningRsp(obj, ctx);
                    break;
                case "setDevIPRsp"://设置终端 IP 地址
                    setDevIPRsp(obj, ctx);
                    break;
                case "getDevIPRsp"://查询 IP 地址信息
                    getDevIPRsp(obj, ctx);
                    break;
                case "setStandingBookRsp"://配置台账信息
                    setStandingBookRsp(obj, ctx);
                    break;
                case "getStandingBookRsp"://查询台账信息
                    getStandingBookRsp(obj, ctx);
                    break;
                case "setOperateRsp"://设置操作人
                    setOperateRsp(obj, ctx);
                    break;
                case "setNetConfigRsp"://设置终端组网配置参数
                    setNetConfigRsp(obj, ctx);
                    break;
                case "getDevLogRsp"://抓取终端 log
                    getDevLogRsp(obj, ctx);
                    break;
                case "getSensorInfoRsp"://读取传感器信息
                    getSensorInfoRsp(obj, ctx);
                    break;
                case "cmdRtSamplingRsp"://召测
                    cmdRtSamplingRsp(obj, ctx);
                    break;
                case "cmdIrBPRRsp"://坏点修复
                    cmdIrBPRRsp(obj, ctx);
                    break;
                case "cmdVideoStreamRsp"://控制终端实时视频
                    cmdVideoStreamRsp(obj, ctx);
                    break;
                case "cmdWiFiHotSpotsRsp"://控制终端热点
                    cmdWiFiHotSpotsRsp(obj, ctx);
                    break;
                case "cmdDevRebootRsp"://控制设备延时重启
                    cmdDevRebootRsp(obj, ctx);
                    break;
                //获取终端文件-通知终端上传文件
                case "getDevFileRsp"://通知终端上传局放 PRPD 和 PRPS 图谱 /通知终端上传红外热图/通知终端上传 SU10 数据
                    getDevFileRsp(obj, ctx);
                    break;
                case "uploadFile"://通用上传文件
                    uploadFile(q_obj,obj, ctx);
                    break;
                case "getDevDataRsp"://获取终端数据
                    getDevDataRsp(obj, ctx);
                    break;
                //终端上传数据
                case "uploadJfStream"://终端上传局放实时视频数据
                    UploadSampData.uploadJfStream(serverHandler,q_obj,obj, ctx);
                    break;
                case "uploadIcuSampleData"://终端上传采样数据（重症监护协议）
                    UploadSampData.uploadIcuSampleData(serverHandler,q_obj,obj, ctx);
                    break;
                case "uploadSampleDataJf"://终端上传特高频局放采样数据
                    UploadSampData.uploadSampleDataJf(serverHandler, q_obj,obj, ctx);
                    break;
                case "uploadSampleDataIr"://终端上传红外采样数据
                    UploadSampData.uploadSampleDataIr(serverHandler,q_obj,obj, ctx);
                    break;
                case "uploadSampleDataCam"://终端上传可见光采样数据
                    UploadSampData.uploadSampleDataCam(serverHandler,q_obj,obj, ctx);
                    break;
                case "uploadSampleDataTH"://终端上传温湿度计采样数据
                    UploadSampData.uploadSampleDataTH(serverHandler,q_obj,obj, ctx);
                    break;
                case "uploadSampleDataSystem"://终端上传系统信息采样数据
                    UploadSampData.uploadSampleDataSystem(serverHandler,q_obj, obj, ctx);
                    break;
                case "uploadSampleDataHfct"://终端上传高频电流传感器采样数据
                    UploadSampData.uploadSampleDataHfct(serverHandler,q_obj,obj, ctx);
                    break;
                case "uploadSampleDataSound"://终端上传声音传感器采样数据
                    UploadSampData.uploadSampleDataSound(serverHandler,q_obj,obj, ctx);
                    break;
                case "uploadSampleDataTev"://终端上传暂态地电压采样数据
                    UploadSampData.uploadSampleDataTev(serverHandler,q_obj,obj, ctx);
                    break;
                case "uploadSampleDataAe"://终端上传超声采样数据
                    UploadSampData.uploadSampleDataAe(serverHandler,q_obj,obj, ctx);
                    break;


                //管理 IED 节点设备
                case "getIedNodeInfoRsp"://查询 IED 节点信息
                    getIedNodeInfoRsp(obj, ctx);
                    break;
                case "setIedSubDevParamRsp"://设置或者编辑从属终端参数
                    setIedSubDevParamRsp(obj, ctx);
                    break;
                case "getIedSubDevParamRsp"://查询从属终端参数
                    getIedSubDevParamRsp(obj, ctx);
                    break;
                case "setIedSampleBandRsp"://设置采样频点
                    setIedSampleBandRsp(obj, ctx);
                    break;
                case "addIedSubDevRsp"://新增从设备
                    addIedSubDevRsp(obj, ctx);
                    break;
                case "delIedSubDevRsp"://删除从设备
                    delIedSubDevRsp(obj, ctx);
                    break;
                case "delAllIedSubDevRsp"://删除全部从设备
                    delAllIedSubDevRsp(obj, ctx);
                    break;
                case "setIedSubDevUploadParamRsp"://配置从设备的上传参数
                    setIedSubDevUploadParamRsp(obj, ctx);
                    break;
                case "cmdRtSamplingModRsp"://召测某个模块
                    cmdRtSamplingModRsp(obj, ctx);
                    break;
//                case "setIedSubDevParamRsp"://设置 SU10 相关参数
//                    setIedSubDevParamRsp(obj,ctx);
//                    break;
                case "keepalive"://心跳检测
                    keepalive(q_obj, obj, ctx);
                    break;
                case "uploadDevAttr"://终端上传状态量和参数属性值
                    uploadDevAttr(q_obj, obj, ctx);
                    break;
                //云台控制功能
                case "cmdYtRotateRsp"://控制云台旋转
                    cmdYtRotateRsp(obj, ctx);
                    break;
                case "addYtTagAnglesRsp"://新增云台标定角度
                    addYtTagAnglesRsp(obj, ctx);
                    break;
                case "delAllYtTagAnglesRsp"://删除所有云台标定角度
                    delAllYtTagAnglesRsp(obj, ctx);
                    break;
                case "delYtTagAnglesRsp"://删除指定的云台标定角度
                    delYtTagAnglesRsp(obj, ctx);
                    break;
                case "setYtTagAnglesRsp"://修改指定的云台标定角度
                    setYtTagAnglesRsp(obj, ctx);
                    break;
                case "getYtTagAnglesRsp"://查询云台标定的角度列表
                    getYtTagAnglesRsp(obj, ctx);
                    break;
                case "setYtTagAngleStateRsp"://设置标定角度是否完成参数配置
                    setYtTagAngleStateRsp(obj, ctx);
                    break;
                case "getYtTagAngleStateRsp"://查询标定角度是否完成参数配置
                    getYtTagAngleStateRsp(obj, ctx);
                    break;
                case "getYtAttrRsp"://查询云台属性
                    getYtAttrRsp(obj, ctx);
                    break;
                case "setYtSupportAttrRsp"://设置云台启用或者禁用
                    setYtSupportAttrRsp(obj, ctx);
                    break;
                case "uploadYtAttr"://终端上报云台属性
                    uploadYtAttr(obj, ctx);
                    break;
                //管理终端连接服务器信息
                case "setServerAddressRsp"://设置终端连接服务器网址和端口
                    setServerAddressRsp(obj, ctx);
                    break;
                case "getServerAddressRsp"://查询终端连接服务器网址和端口号
                    getServerAddressRsp(obj, ctx);
                    break;
                case "无"://其它预留接口

                    break;
                default:
                    logger.error("decodemessagedata  非解析信息：" + action);
                    break;
            }
        } catch (Exception ex) {
            logger.error("decodemessagedata error： " + ex);
        }
    }

    private void uploadYtAttr(JSONObject obj, ChannelHandlerContext ctx) {
        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("uploadYtAttr error： " + ex);
        }
    }

    private void setYtSupportAttrRsp(JSONObject obj, ChannelHandlerContext ctx) {
        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("setYtSupportAttrRsp error： " + ex);
        }
    }

    private void getYtAttrRsp(JSONObject obj, ChannelHandlerContext ctx) {
        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("getYtAttrRsp error： " + ex);
        }
    }

    private void getYtTagAngleStateRsp(JSONObject obj, ChannelHandlerContext ctx) {
        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("getYtTagAngleStateRsp error： " + ex);
        }
    }

    private void setYtTagAngleStateRsp(JSONObject obj, ChannelHandlerContext ctx) {
        logger.debug("setYtTagAngleStateRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("setYtTagAngleStateRsp error： " + ex);
        }
    }

    private void getYtTagAnglesRsp(JSONObject obj, ChannelHandlerContext ctx) {
        logger.debug("getYtTagAnglesRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("getYtTagAnglesRsp error： " + ex);
        }
    }

    private void setYtTagAnglesRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("setYtTagAnglesRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("setYtTagAnglesRsp error： " + ex);
        }
    }

    private void delYtTagAnglesRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("delYtTagAnglesRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("delYtTagAnglesRsp error： " + ex);
        }
    }

    private void delAllYtTagAnglesRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("delAllYtTagAnglesRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("delAllYtTagAnglesRsp error： " + ex);
        }
    }

    private void addYtTagAnglesRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("addYtTagAnglesRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("addYtTagAnglesRsp error： " + ex);
        }
    }

    //终端主动授时请求
    private void requestSyncTime(JSONObject q_obj, JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("requestSyncTime");
        try {
            JSONObject contentobj = new JSONObject();
            JSONObject dateTimeobj = new JSONObject();
            logger.debug("时间戳：" + new Date().getTime());
            dateTimeobj.put("dateTime", "" + new Date().getTime());
            contentobj.put("DevConfig", dateTimeobj);
            //入库或页面提示
            sendJsonResMsgOKorERROR("requestSyncTimeRsp", Constant.CMD_OK, null, q_obj, "content", contentobj, ctx);
        } catch (Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }

//        "action": "requestSyncTimeRsp",
//                "msgId": "",
//                "result": "ok",
//                "msg": "授时成功",
//        "content": {
//            "DevConfig": {
//                "dateTime": "1514707265557"
//            }
//        }
    }

    //心跳
    private void keepalive(JSONObject q_obj, JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("keepalive");
        try {

            JSONObject contentobj = new JSONObject();
            contentobj = obj.getJSONObject("content");
            if(contentobj != null){
                JSONArray OnlineDevIdsarray = contentobj.getJSONArray("OnlineDevIds");
                if(OnlineDevIdsarray.size() > 0) {
                    for (int i = 0; i < OnlineDevIdsarray.size(); i++) {
                        String OnlineDevIdStr = OnlineDevIdsarray.getString(i);
                        //入库或更新操作
                        TBusiDevStatusInfoEntity tBusiDevStatusInfoEntityIDS = new TBusiDevStatusInfoEntity();
                        tBusiDevStatusInfoEntityIDS.setDevCode(OnlineDevIdStr.trim());
                        tBusiDevStatusInfoEntityIDS.setIsVaild("1");
                        tBusiDevStatusInfoEntityIDS.setLastOpr((long) 0);
                        tBusiDevStatusInfoEntityIDS.setLastTime(new Date());
                        serverHandler.tBusiDevStatusInfoService.updateDevStatusInfoByCode(tBusiDevStatusInfoEntityIDS);
                    }
                }
            }

//            "content":{"OnlineDevIds":[
            JSONObject privateaminformation = q_obj.getJSONObject("私有协议消息");
            logger.debug("私有协议消息:" + privateaminformation);
            String sessionid = privateaminformation.getString("会话编号");
            logger.debug("会话编号:" + sessionid.trim());
            //入库或页面提示
            TBusiDevStatusInfoEntity tBusiDevStatusInfoEntity = new TBusiDevStatusInfoEntity();
            tBusiDevStatusInfoEntity.setDevCode(sessionid.trim());
//            tBusiDevStatusInfoEntity.setDevStatus("1");
            tBusiDevStatusInfoEntity.setIsVaild("1");
            tBusiDevStatusInfoEntity.setLastOpr((long) 0);
            tBusiDevStatusInfoEntity.setLastTime(new Date());
            int updsum = serverHandler.tBusiDevStatusInfoService.updateDevStatusInfoByCode(tBusiDevStatusInfoEntity);
            if (updsum <= 0) {
                tBusiDevStatusInfoEntity.setIsVaild("1");
                tBusiDevStatusInfoEntity.setDevStatus("1");
                tBusiDevStatusInfoEntity.setIsAlarm("0");
                tBusiDevStatusInfoEntity.setCreateOpr((long) 0);
                tBusiDevStatusInfoEntity.setCreateTime(new Date());
//                boolean saveflag = serverHandler.tBusiDevStatusInfoService.save(tBusiDevStatusInfoEntity);
//                if (!saveflag) {
//                    logger.error("保存数据库失败 KeepaliveRsp tBusiDevStatusInfoEntity");
//                    sendJsonResMsgOKorERROR("KeepaliveRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
//                    return;
//                }
            }
            sendJsonResMsgOKorERROR("KeepaliveRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);
//            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("keepalive error： " + ex);
        }
    }

    private void setIedSubDevUploadParamRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("setIedSubDevUploadParamRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            //入库或更新操作
            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("setIedSubDevUploadParamRsp error： " + ex);
        }
    }

    private void delAllIedSubDevRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("delAllIedSubDevRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            //入库或更新操作
            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("delAllIedSubDevRsp error： " + ex);
        }
    }

    private void delIedSubDevRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("delIedSubDevRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            //入库或更新操作
            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("delIedSubDevRsp error： " + ex);
        }
    }

    private void addIedSubDevRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("addIedSubDevRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("成功");
            result.equals("error");
            msg.equals("失败");
            //入库或更新操作
            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("addIedSubDevRsp error： " + ex);
        }
    }

    private void setIedSampleBandRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("setIedSampleBandRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("SU10频段信息");
            result.equals("error");
            msg.equals("设备忙，失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONArray IedSubDevAttrarray = contentobj.getJSONArray("IedSubDevAttr");
            for (int i = 0; i < IedSubDevAttrarray.size(); i++) {
                JSONObject IedSubDevAttrobj = IedSubDevAttrarray.getJSONObject(i);
                String sampleBand = IedSubDevAttrobj.getString("sampleBand");
                //入库或更新操作
            }

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }
//        "action": "setIedSampleBandRsp",
//                "result": "ok",
//                "msg": "SU10频段信息",
//                "content": {
//            "IedSubDevAttr": [
//            {
//                "sampleBand": "1"
//            }
//]
//        }
    }

    private void getIedSubDevParamRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("getIedSubDevParamRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("获取 ied 从属设备参数成功");
            result.equals("error");
            msg.equals("设备忙，失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONArray IedSubDevAttrarray = contentobj.getJSONArray("IedSubDevAttr");
            for (int i = 0; i < IedSubDevAttrarray.size(); i++) {
                JSONObject IedSubDevAttrobj = IedSubDevAttrarray.getJSONObject(i);
                String devId = IedSubDevAttrobj.getString("devId");
                String devProduct = IedSubDevAttrobj.getString("devProduct");
                String devSrc = IedSubDevAttrobj.getString("devSrc");
                String devType = IedSubDevAttrobj.getString("devType");
                String listenInterval = IedSubDevAttrobj.getString("listenInterval");
                String macAddr = IedSubDevAttrobj.getString("macAddr");
                String sampkeInterval = IedSubDevAttrobj.getString("sampkeInterval");
                String sampleBand = IedSubDevAttrobj.getString("sampleBand");
                String sampleDurationTime = IedSubDevAttrobj.getString("sampleDurationTime");
                String sampleFreq = IedSubDevAttrobj.getString("sampleFreq");
                String sampleStartTime = IedSubDevAttrobj.getString("sampleStartTime");
                //入库或更新操作
            }

            logger.debug(result + msg);
        } catch (Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }
//        "action": "getIedSubDevParamRsp",
//                "result": "ok",
//                "msg": "获取 ied 从属设备参数成功",
//                "content": {
//            "IedSubDevAttr": [
//            {
//                "devId": "MP03MN1191101000007",
//                    "devProduct": "SU10",
//                    "devSrc": "ied",
//                    "devType": "120",
//                    "listenInterval": "-1",
//                    "macAddr": "30,30,30,37",
//                    "sampkeInterval": "-1",
//                    "sampleBand": "0",
//                    "sampleDurationTime": "-1",
//                    "sampleFreq": "-1",
//                    "sampleStartTime": "-1-1-1"
//            }
//]
//        }
    }

    private void uploadSampleDataSound(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataSound");
        try {
//            String msgId = obj.getString("msgId");

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject SoundSampleDataobj = contentobj.getJSONObject("SoundSampleData");
            JSONObject SampleDataBaseobj = SoundSampleDataobj.getJSONObject("SampleDataBase");
            String devSrc = SampleDataBaseobj.getString("devSrc");
            String devId = SampleDataBaseobj.getString("devId");
            String module = SampleDataBaseobj.getString("module");
            String time = SampleDataBaseobj.getString("time");
            String state = SampleDataBaseobj.getString("state");
            JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
            String type = ExceptionInfoobj.getString("type");
            String msg = ExceptionInfoobj.getString("msg");

            String fileSound = contentobj.getString("fileSound");
            //入库或更新操作

            sendJsonResMsgOKorERROR("uploadSampleDataSoundRsp", Constant.CMD_OK, null, obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }
//        "action": "uploadSampleDataSound",
//                "msgId": "",
//                "content": {
//            "SoundSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "ied",
//                            "devId": "SU10AX123450007",
//                            "module": "Sound",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "fileSound": "20190629_100013_511_sound.wav"
//            }
//        }
    }

    private void uploadSampleDataHfct(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataHfct");
        try {
//            String msgId = obj.getString("msgId");
            TSampJfDataInfoEntity tSampJfDataInfoEntity = new TSampJfDataInfoEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            if (contentobj != null) {
                JSONObject JfSampleDataobj = contentobj.getJSONObject("JfSampleData");
                if (JfSampleDataobj != null) {
                    JSONObject SampleDataBaseobj = JfSampleDataobj.getJSONObject("SampleDataBase");
                    if (SampleDataBaseobj != null) {
                        String devSrc = SampleDataBaseobj.getString("devSrc");
                        String devId = SampleDataBaseobj.getString("devId");
                        String module = SampleDataBaseobj.getString("module");
                        String time = SampleDataBaseobj.getString("time");
                        String state = SampleDataBaseobj.getString("state");
                        JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                        if (ExceptionInfoobj != null) {
                            String type = ExceptionInfoobj.getString("type");
                            String msg = ExceptionInfoobj.getString("msg");
                            tSampBasiDataInfoEntity.setSampExceptionType(type);
                            tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                        }

                        tSampBasiDataInfoEntity.setDevSrc(devSrc);
                        tSampBasiDataInfoEntity.setDevId(devId);
                        tSampBasiDataInfoEntity.setModuleName(module);
                        tSampBasiDataInfoEntity.setSampTime(time);
                        tSampBasiDataInfoEntity.setSampState(state);
                        tSampBasiDataInfoEntity.setCreateTime(new Date());
                        tSampBasiDataInfoEntity.setLastTime(new Date());

                        tSampJfDataInfoEntity.setDevId(devId);
                    }
                }

                String AvDsch = contentobj.getString("AvDsch");
                String MaxDsch = contentobj.getString("MaxDsch");
                String DschCnt = contentobj.getString("DschCnt");
                String DschPhase = contentobj.getString("DschPhase");
                String filePrpd = contentobj.getString("filePrpd");
                String filePrps = contentobj.getString("filePrps");
                tSampJfDataInfoEntity.setAvDsch(AvDsch);
                tSampJfDataInfoEntity.setMaxDsch(MaxDsch);
                tSampJfDataInfoEntity.setDschCnt(DschCnt);
                tSampJfDataInfoEntity.setDschPhase(DschPhase);
                tSampJfDataInfoEntity.setFilePrpd(filePrpd);
                tSampJfDataInfoEntity.setFilePrps(filePrps);
                //入库或更新操作

                logger.debug("保存数据库------");
                boolean saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataHfctRsp tSampBasiDataInfoEntity");
                    sendJsonResMsgOKorERROR("uploadSampleDataHfctRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                    return;
                }
                saveflag = serverHandler.tSampJfDataInfoService.save(tSampJfDataInfoEntity);
                if (!saveflag) {
                    logger.error("保存数据库失败 uploadSampleDataHfctRsp tSampJfDataInfoEntity");
                    sendJsonResMsgOKorERROR("uploadSampleDataHfctRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                    return;
                }
                logger.debug("保存数据库完成");
            }

            sendJsonResMsgOKorERROR("uploadSampleDataHfctRsp", Constant.CMD_OK, null, obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataHfctRsp error： " + ex);
        }
//        "action": "uploadSampleDataHfct",
//                "msgId": "",
//                "content": {
//            "JfSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "ied",
//                            "devId": "SU10AX123450007",
//                            "module": "HFCT",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "AvDsch": "196",
//                        "MaxDsch": "687",
//                        "DschCnt": "1156",
//                        "DschPhase": "258",
//                        "filePrpd": "20190629_100013_511_prpd.png",
//                        "filePrps": "20190629_160616_088_prps.png"
//            }
//        }
    }

    private void uploadSampleDataSystem(JSONObject q_obj, JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataSystem");
        try {
            String msgId = obj.getString("msgId");

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject DevSystemDataobj = contentobj.getJSONObject("DevSystemData");
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();
            TSampDevDataInfoEntity tSampDevDataInfoEntity = new TSampDevDataInfoEntity();
            if (DevSystemDataobj != null) {
                JSONObject SampleDataBaseobj = DevSystemDataobj.getJSONObject("SampleDataBase");
                if (SampleDataBaseobj != null) {
                    logger.debug("SampleDataBaseobj");
                    String devSrc = SampleDataBaseobj.getString("devSrc");
                    String devId = SampleDataBaseobj.getString("devId");
                    String module = SampleDataBaseobj.getString("module");
                    String time = SampleDataBaseobj.getString("time");
                    String state = SampleDataBaseobj.getString("state");
                    JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                    if (ExceptionInfoobj != null) {
                        logger.debug("ExceptionInfoobj");
                        String type = ExceptionInfoobj.getString("type");
                        String msg = ExceptionInfoobj.getString("msg");
                        tSampBasiDataInfoEntity.setSampExceptionType(type);
                        tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                    }
                    tSampBasiDataInfoEntity.setDevSrc(devSrc);
                    tSampBasiDataInfoEntity.setDevId(devId);
                    tSampBasiDataInfoEntity.setModuleName(module);
                    tSampBasiDataInfoEntity.setSampTime(time);
                    tSampBasiDataInfoEntity.setSampState(state);
                    tSampBasiDataInfoEntity.setCreateTime(new Date());
                    tSampBasiDataInfoEntity.setLastTime(new Date());

                    tSampDevDataInfoEntity.setDevId(devId);
                }
                JSONObject IPInfoobj = DevSystemDataobj.getJSONObject("IPInfo");
                if (IPInfoobj != null) {
                    logger.debug("IPInfoobj");
                    String ipVersion = IPInfoobj.getString("ipVersion");
                    String ipType = IPInfoobj.getString("ipType");
                    String ipAddress = IPInfoobj.getString("ipAddress");
                    String mask = IPInfoobj.getString("mask");
                    String gateway = IPInfoobj.getString("gateway");
                    String dns = IPInfoobj.getString("dns");

                    tSampDevDataInfoEntity.setIpVersion(ipVersion);
                    tSampDevDataInfoEntity.setIpType(ipType);
                    tSampDevDataInfoEntity.setIpAddress(ipAddress);
                    tSampDevDataInfoEntity.setIpMask(mask);
                    tSampDevDataInfoEntity.setIpGateway(gateway);
                    tSampDevDataInfoEntity.setIpDns(dns);
                }
                JSONObject WiFiInfoobj = DevSystemDataobj.getJSONObject("WiFiInfo");
                if (WiFiInfoobj != null) {
                    logger.debug("WiFiInfoobj");
                    String ssid = WiFiInfoobj.getString("ssid");
                    String wifiEnable = WiFiInfoobj.getString("wifiEnable");

                    tSampDevDataInfoEntity.setWifiSsid(ssid);
                    tSampDevDataInfoEntity.setWifiStatus(wifiEnable);
                }
                JSONObject SimInfoobj = DevSystemDataobj.getJSONObject("SimInfo");
                if (SimInfoobj != null) {
                    logger.debug("SimInfoobj");
                    String signalLevel = SimInfoobj.getString("signalLevel");
                    String phoneNumber = SimInfoobj.getString("phoneNumber");

                    tSampDevDataInfoEntity.setSimSignalLevel(signalLevel);
                    tSampDevDataInfoEntity.setSimPhoneNumber(phoneNumber);
                }

                String deviceName = DevSystemDataobj.getString("deviceName");
                String serial = DevSystemDataobj.getString("serial");
                String version = DevSystemDataobj.getString("version");
                String gps = DevSystemDataobj.getString("gps");
                String cpu = DevSystemDataobj.getString("cpu");
                String rom = DevSystemDataobj.getString("rom");
                String ram = DevSystemDataobj.getString("ram");
                String cpuTemp = DevSystemDataobj.getString("cpuTemp");
                String boardTemp = DevSystemDataobj.getString("boardTemp");
                String batteryLevel = DevSystemDataobj.getString("batteryLevel");
                String batteryTemp = DevSystemDataobj.getString("batteryTemp");
                String hwVersion = DevSystemDataobj.getString("hwVersion");
                String loraVersion = DevSystemDataobj.getString("loraVersion");
                String chargerState = DevSystemDataobj.getString("chargerState");
                String snr = DevSystemDataobj.getString("snr");
                String rssi = DevSystemDataobj.getString("rssi");

                tSampDevDataInfoEntity.setDeviceName(deviceName);
                tSampDevDataInfoEntity.setSerial(serial);
                tSampDevDataInfoEntity.setVersion(version);
                tSampDevDataInfoEntity.setGps(gps);
                tSampDevDataInfoEntity.setCpu(cpu);
                tSampDevDataInfoEntity.setRom(rom);
                tSampDevDataInfoEntity.setRam(ram);
                tSampDevDataInfoEntity.setCpuTemp(cpuTemp);
                tSampDevDataInfoEntity.setBoardTemp(boardTemp);
                tSampDevDataInfoEntity.setBatteryLevel(batteryLevel);
                tSampDevDataInfoEntity.setBatteryTemp(batteryTemp);
                tSampDevDataInfoEntity.setHwVersion(hwVersion);
                tSampDevDataInfoEntity.setLoraVersion(loraVersion);
                tSampDevDataInfoEntity.setChargerState(chargerState);
                tSampDevDataInfoEntity.setSnr(snr);
                tSampDevDataInfoEntity.setRssi(rssi);

                tSampDevDataInfoEntity.setCreateTime(new Date());
                tSampDevDataInfoEntity.setLastTime(new Date());
            }
            //入库或更新操作

            logger.debug("保存数据库操作------");
            boolean saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
            if (!saveflag) {
                logger.error("保存数据库操作失败 uploadSampleDataSystemRsp tSampBasiDataInfoEntity");
                sendJsonResMsgOKorERROR("uploadSampleDataSystemRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                return;
            }
            saveflag = serverHandler.tSampDevDataInfoService.save(tSampDevDataInfoEntity);
            if (!saveflag) {
                logger.error("保存数据库操作失败 uploadSampleDataSystemRsp tSampDevDataInfoEntity");
                sendJsonResMsgOKorERROR("uploadSampleDataSystemRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                return;
            }
            logger.debug("保存数据库操作完成");

            sendJsonResMsgOKorERROR("uploadSampleDataSystemRsp", Constant.CMD_OK, null, q_obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataSystem error： " + ex);
        }
//        "action": "uploadSampleDataSystem",
//                "content": {
//            "DevSystemData": {
//                "SampleDataBase": {
//                    "devSrc": "dev",
//                            "devId": "TP01MN2181221000042",
//                            "module": "system",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "IPInfo": {
//                    "ipVersion": "IPv4",
//                            "ipType": "dhcp",
//                            "ipAddress": "192.168.0.184",
//                            "mask": "255.255.255.0",
//                            "gateway": "",
//                            "dns": ""
//                },
//                "WiFiInfo": {
//                    "ssid": "MN-MP01MN1190601000232",
//                    "wifiEnable": "关闭"
//                },
//                "SimInfo": {
//                    "signalLevel": "0",
//                            "phoneNumber": ""
//                },
//                "deviceName": "T2000",
//                        "serial": "MP01MN1190601000232",
//                        "version": "T2000__CH_U_V190715BCF2FF21",
//                        "gps": ",",
//                        "cpu": "26.1%",
//                        "rom": "5%",
//                        "ram": "52%",
//                        "cpuTemp": "37",
//                        "boardTemp": "32",
//                        "batteryLevel": "255",
//                        "batteryTemp": "55",
//                        "hwVersion": "V1.0",
//                        "loraVersion": "V1.1",
//                        "chargerState": "0",
//                        "snr": "15",
//                        "rssi": "13"
//            }
//        }
    }

    private void uploadSampleDataTH(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataTH");
        try {
            String msgId = obj.getString("msgId");
            TSampThDataInfoEntity tSampThDataInfoEntity = new TSampThDataInfoEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject THSampleDataobj = contentobj.getJSONObject("THSampleData");
            if (THSampleDataobj != null) {
                JSONObject SampleDataBaseobj = THSampleDataobj.getJSONObject("SampleDataBase");
                if (SampleDataBaseobj != null) {
                    logger.debug("SampleDataBaseobj");
                    String devSrc = SampleDataBaseobj.getString("devSrc");
                    String devId = SampleDataBaseobj.getString("devId");
                    String module = SampleDataBaseobj.getString("module");
                    String time = SampleDataBaseobj.getString("time");
                    String state = SampleDataBaseobj.getString("state");
                    JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                    if (ExceptionInfoobj != null) {
                        logger.debug("ExceptionInfoobj");
                        String type = ExceptionInfoobj.getString("type");
                        String msg = ExceptionInfoobj.getString("msg");
                        tSampBasiDataInfoEntity.setSampExceptionType(type);
                        tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                    }
                    tSampBasiDataInfoEntity.setDevSrc(devSrc);
                    tSampBasiDataInfoEntity.setDevId(devId);
                    tSampBasiDataInfoEntity.setModuleName(module);
                    tSampBasiDataInfoEntity.setSampTime(time);
                    tSampBasiDataInfoEntity.setSampState(state);
                    tSampBasiDataInfoEntity.setCreateTime(new Date());
                    tSampBasiDataInfoEntity.setLastTime(new Date());

                    tSampThDataInfoEntity.setDevId(devId);
                }

                String ambientTemp = contentobj.getString("ambientTemp");
                String relativeHumidity = contentobj.getString("relativeHumidity");
                String pressure = contentobj.getString("pressure");

                tSampThDataInfoEntity.setAmbientTemp(ambientTemp);
                tSampThDataInfoEntity.setRelativeHumidity(relativeHumidity);
                tSampThDataInfoEntity.setPressure(pressure);
                tSampThDataInfoEntity.setCreateTime(new Date());
                tSampThDataInfoEntity.setLastTime(new Date());
            }
            //入库或更新操作
            logger.debug("保存数据------");
            boolean saveflag = serverHandler.tSampThDataInfoService.save(tSampThDataInfoEntity);
            if (!saveflag) {
                logger.error("保存数据库失败 uploadSampleDataTHRsp tSampThDataInfoEntity");
                sendJsonResMsgOKorERROR("uploadSampleDataTHRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                return;
            }
            saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
            if (!saveflag) {
                logger.error("保存数据库失败 uploadSampleDataTHRsp tSampBasiDataInfoEntity");
                sendJsonResMsgOKorERROR("uploadSampleDataTHRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                return;
            }

            sendJsonResMsgOKorERROR("uploadSampleDataTHRsp", Constant.CMD_OK, null, obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }
//        "action": "uploadSampleDataTH",
//                "content": {
//            "THSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "dev",
//                            "devId": "TP01MN2181221000042",
//                            "module": "TH",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "ambientTemp": "26.92",
//                        "relativeHumidity": "69.98",
//                        "pressure": ""
//            }
//        }
    }

    private void uploadSampleDataCam(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataCam");
        try {
            String msgId = obj.getString("msgId");
            TSampCameraDataInfoEntity tSampCameraDataInfoEntity = new TSampCameraDataInfoEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject CameraSampleDataobj = contentobj.getJSONObject("CameraSampleData");
            if (CameraSampleDataobj != null) {
                JSONObject SampleDataBaseobj = CameraSampleDataobj.getJSONObject("SampleDataBase");
                if (SampleDataBaseobj != null) {
                    logger.debug("SampleDataBaseobj");
                    String devSrc = SampleDataBaseobj.getString("devSrc");
                    String devId = SampleDataBaseobj.getString("devId");
                    String module = SampleDataBaseobj.getString("module");
                    String time = SampleDataBaseobj.getString("time");
                    String state = SampleDataBaseobj.getString("state");
                    JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                    if (ExceptionInfoobj != null) {
                        logger.debug("ExceptionInfoobj");
                        String type = ExceptionInfoobj.getString("type");
                        String msg = ExceptionInfoobj.getString("msg");
                        tSampBasiDataInfoEntity.setSampExceptionType(type);
                        tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                    }
                    tSampBasiDataInfoEntity.setDevSrc(devSrc);
                    tSampBasiDataInfoEntity.setDevId(devId);
                    tSampBasiDataInfoEntity.setModuleName(module);
                    tSampBasiDataInfoEntity.setSampTime(time);
                    tSampBasiDataInfoEntity.setSampState(state);
                    tSampBasiDataInfoEntity.setCreateTime(new Date());
                    tSampBasiDataInfoEntity.setLastTime(new Date());

                    tSampCameraDataInfoEntity.setDevId(devId);
                }

                String fileCamImg = CameraSampleDataobj.getString("fileCamImg");
                String fileCamSobelImg = CameraSampleDataobj.getString("fileCamSobelImg");
                String fileCamIdImg = CameraSampleDataobj.getString("fileCamIdImg");
                String fileCamVideo = CameraSampleDataobj.getString("fileCamVideo");

                tSampCameraDataInfoEntity.setFileCamImg(fileCamImg);
                tSampCameraDataInfoEntity.setFileSobeImg(fileCamSobelImg);
                tSampCameraDataInfoEntity.setFileCamIdImg(fileCamIdImg);
                tSampCameraDataInfoEntity.setFileCamVideo(fileCamVideo);
                tSampCameraDataInfoEntity.setCreateTime(new Date());
                tSampCameraDataInfoEntity.setLastTime(new Date());
            }
            //入库或更新操作
            boolean saveflag = serverHandler.tSampCameraDataInfoService.save(tSampCameraDataInfoEntity);
            if (!saveflag) {
                logger.error("保存数据库失败 uploadSampleDataCamRsp tSampCameraDataInfoEntity");
                sendJsonResMsgOKorERROR("uploadSampleDataCamRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                return;
            }
            saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
            if (!saveflag) {
                logger.error("保存数据库失败 uploadSampleDataCamRsp tSampBasiDataInfoEntity");
                sendJsonResMsgOKorERROR("uploadSampleDataCamRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                return;
            }

            sendJsonResMsgOKorERROR("uploadSampleDataCamRsp", Constant.CMD_OK, null, obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataCam error： " + ex);
        }
//        "action": "uploadSampleDataCam",
//                "msgId": "",
//                "content": {
//            "CameraSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "dev",
//                            "devId": "TP01MN2181221000042",
//                            "module": "Camera",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "fileCamImg": "20190928_155226.jpg",
//                        "fileCamSobelImg": "20190928_155226_sobel.jpg",
//                "fileCamIdImg": "20190928_155226_id.jpg",
//                        "fileCamVideo": "20190928_155226_video.mp4"
//            }
//        }
    }

    private void uploadSampleDataIr(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadSampleDataIr");
        try {
            String msgId = obj.getString("msgId");
            TSampIrDataInfoEntity tSampIrDataInfoEntity = new TSampIrDataInfoEntity();
            TSampIrSensorTempEntity tSampIrSensorTempEntity = new TSampIrSensorTempEntity();
            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject IrSampleDataobj = contentobj.getJSONObject("IrSampleData");
            if (IrSampleDataobj != null) {
                JSONObject SampleDataBaseobj = IrSampleDataobj.getJSONObject("SampleDataBase");
                if (SampleDataBaseobj != null) {
                    String devSrc = SampleDataBaseobj.getString("devSrc");
                    String devId = SampleDataBaseobj.getString("devId");
                    String module = SampleDataBaseobj.getString("module");
                    String time = SampleDataBaseobj.getString("time");
                    String state = SampleDataBaseobj.getString("state");
                    JSONObject ExceptionInfoobj = SampleDataBaseobj.getJSONObject("ExceptionInfo");
                    if (ExceptionInfoobj != null) {
                        String type = ExceptionInfoobj.getString("type");
                        String msg = ExceptionInfoobj.getString("msg");
                        tSampBasiDataInfoEntity.setSampExceptionType(type);
                        tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
                    }
                    tSampBasiDataInfoEntity.setDevSrc(devSrc);
                    tSampBasiDataInfoEntity.setDevId(devId);
                    tSampBasiDataInfoEntity.setModuleName(module);
                    tSampBasiDataInfoEntity.setSampTime(time);
                    tSampBasiDataInfoEntity.setSampState(state);
                    tSampBasiDataInfoEntity.setCreateTime(new Date());
                    tSampBasiDataInfoEntity.setLastTime(new Date());

                    tSampIrDataInfoEntity.setDevId(devId);
                    JSONArray IrTemparray = IrSampleDataobj.getJSONArray("IrTemp");
                    if (IrTemparray != null) {
                        for (int i = 0; i < IrTemparray.size(); i++) {
                            JSONObject IrTempobj = IrTemparray.getJSONObject(i);
                            String name = IrTempobj.getString("name");
                            String maxTemp = IrTempobj.getString("maxTemp");
                            String minTemp = IrTempobj.getString("minTemp");

                            tSampIrSensorTempEntity.setDevId(devId);
                            tSampIrSensorTempEntity.setAreaName(name);
                            tSampIrSensorTempEntity.setAreaMaxTemp(maxTemp);
                            tSampIrSensorTempEntity.setAreaMinTemp(minTemp);

                            tSampIrSensorTempEntity.setCreateTime(new Date());
                            tSampIrSensorTempEntity.setLastTime(new Date());

                            boolean saveflag = serverHandler.tSampIrSensorTempService.save(tSampIrSensorTempEntity);
                            if (!saveflag) {
                                logger.error("保存数据库失败 uploadSampleDataIrRsp tSampIrSensorTempEntity");
                                sendJsonResMsgOKorERROR("uploadSampleDataIrRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                                return;
                            }
                        }
                    }
                }

                String irModType = IrSampleDataobj.getString("irModType");
                String fileTemp = IrSampleDataobj.getString("fileTemp");
                String fileIrImg = IrSampleDataobj.getString("fileIrImg");
                String fileOvTemp = IrSampleDataobj.getString("fileOvTemp");
                String fileOvImg = IrSampleDataobj.getString("fileOvImg");

                tSampIrDataInfoEntity.setIrModType(irModType);
                tSampIrDataInfoEntity.setFileTemp(fileTemp);
                tSampIrDataInfoEntity.setFileIrImg(fileIrImg);
                tSampIrDataInfoEntity.setFileOvTemp(fileOvTemp);
                tSampIrDataInfoEntity.setFileOvImg(fileOvImg);
                tSampIrDataInfoEntity.setCreateTime(new Date());
                tSampIrDataInfoEntity.setLastTime(new Date());
            }
            //入库或更新操作
            boolean saveflag = serverHandler.tSampIrDataInfoService.save(tSampIrDataInfoEntity);
            if (!saveflag) {
                logger.error("保存数据库失败 uploadSampleDataIrRsp tSampIrDataInfoEntity");
                sendJsonResMsgOKorERROR("uploadSampleDataIrRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                return;
            }
            saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
            if (!saveflag) {
                logger.error("保存数据库失败 uploadSampleDataIrRsp tSampBasiDataInfoEntity");
                sendJsonResMsgOKorERROR("uploadSampleDataIrRsp", Constant.CMD_ERROR, null, obj, null, null, ctx);
                return;
            }

            sendJsonResMsgOKorERROR("uploadSampleDataIrRsp", Constant.CMD_OK, null, obj, null, null, ctx);

        } catch (Exception ex) {
            logger.error("uploadSampleDataIr error： " + ex);
        }
//        "action": "uploadSampleDataIr",
//                "msgId": "",
//                "content": {
//            "IrSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "dev",
//                            "devId": "TP01MN2181221000042",
//                            "module": "IR",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "IrTemp": [
//                {
//                    "name": "ALL",
//                        "maxTemp": "33.76",
//                        "minTemp": "19.09"
//                },
//                {
//                    "name": "A",
//                        "maxTemp": "27.1",
//                        "minTemp": "19.95"
//                },
//                {
//                    "name": "B",
//                        "maxTemp": "33.0",
//                        "minTemp": "20.08"
//                },
//                {
//                    "name": "C",
//                        "maxTemp": "33.76",
//                        "minTemp": "19.09"
//                }
//],
//                "irModType": "thermapp",
//                        "fileTemp": "20190928_155227_854_temp.txt",
//                        "fileIrImg": "20190928_155224_357_therm.png",
//                        "fileOvTemp": "20190928_155227_854_ov_temp.txt",
//                        "fileOvImg": "20190928_155228_938_ov.png"
//            }
//        }
    }

//    private void uploadSampleDataJf(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("uploadSampleDataJf");
//        try {
//            String msgId = obj.getString("msgId");
//            TSampJfDataInfoEntity tSampJfDataInfoEntity = new TSampJfDataInfoEntity();
//            TSampBasiDataInfoEntity tSampBasiDataInfoEntity = new TSampBasiDataInfoEntity();
//
//            JSONObject contentobj = obj.getJSONObject("content");
//            JSONObject JfSampleDataobj = contentobj.getJSONObject("JfSampleData");
//            if(JfSampleDataobj != null) {
//                JSONObject SampleDataBase = JfSampleDataobj.getJSONObject("SampleDataBase");
//                String devSrc = SampleDataBase.getString("devSrc");
//                String devId = SampleDataBase.getString("devId");
//                String module = SampleDataBase.getString("module");
//                String time = SampleDataBase.getString("time");
//                String state = SampleDataBase.getString("state");
//                JSONObject ExceptionInfoobj = SampleDataBase.getJSONObject("ExceptionInfo");
//                if(ExceptionInfoobj != null) {
//                    String type = ExceptionInfoobj.getString("type");
//                    String msg = ExceptionInfoobj.getString("msg");
//
//                    tSampBasiDataInfoEntity.setSampExceptionType(type);
//                    tSampBasiDataInfoEntity.setSampExceptionMsg(msg);
//                }
//                tSampBasiDataInfoEntity.setDevSrc(devSrc);
//                tSampBasiDataInfoEntity.setDevId(devId);
//                tSampBasiDataInfoEntity.setModuleName(module);
//                tSampBasiDataInfoEntity.setSampTime(time);
//                tSampBasiDataInfoEntity.setSampState(state);
//                tSampBasiDataInfoEntity.setCreateTime(new Date());
//                tSampBasiDataInfoEntity.setLastTime(new Date());
//
//                tSampJfDataInfoEntity.setDevId(devId);
//            }
//
//            String AvDsch = contentobj.getString("AvDsch");
//            String MaxDsch = contentobj.getString("MaxDsch");
//            String DschCnt = contentobj.getString("DschCnt");
//            String DschPhase = contentobj.getString("DschPhase");
//            String filePrpd = contentobj.getString("filePrpd");
//            String filePrps = contentobj.getString("filePrps");
//
//            tSampJfDataInfoEntity.setAvDsch(AvDsch);
//            tSampJfDataInfoEntity.setMaxDsch(MaxDsch);
//            tSampJfDataInfoEntity.setDschCnt(DschCnt);
//            tSampJfDataInfoEntity.setDschPhase(DschPhase);
//            tSampJfDataInfoEntity.setFilePrpd(filePrpd);
//            tSampJfDataInfoEntity.setFilePrps(filePrps);
//            //入库或更新操作
//
//            logger.debug("保存数据库------");
//            boolean saveflag = serverHandler.tSampBasiDataInfoService.save(tSampBasiDataInfoEntity);
//            if(!saveflag){
//                logger.error("保存数据库失败 uploadSampleDataJfRsp tSampBasiDataInfoEntity");
//                sendJsonResMsgOKorERROR("uploadSampleDataJfRsp",Constant.CMD_ERROR,null,obj,null,null,ctx);
//                return;
//            }
//            saveflag = serverHandler.tSampJfDataInfoService.save(tSampJfDataInfoEntity);
//            if(!saveflag){
//                logger.error("保存数据库失败 uploadSampleDataJfRsp tSampJfDataInfoEntity");
//                sendJsonResMsgOKorERROR("uploadSampleDataJfRsp",Constant.CMD_ERROR,null,obj,null,null,ctx);
//                return;
//            }
//            logger.debug("保存数据库完成");
//
//            sendJsonResMsgOKorERROR("uploadSampleDataJfRsp",Constant.CMD_OK,null,obj,null,null,ctx);
//
//        }catch(Exception ex) {
//            logger.error("uploadSampleDataJf error： " + ex);
//        }
//}
//        "action": "uploadSampleDataJf",
//                "msgId": "",
//                "content": {
//            "JfSampleData": {
//                "SampleDataBase": {
//                    "devSrc": "ied",
//                            "devId": "SU10AX123450007",
//                            "module": "UHF",
//                            "time": "2019-08-22 08:17:58",
//                            "state": "normal",
//                            "ExceptionInfo": {
//                        "type": "1",
//                                "msg": "88%"
//                    }
//                },
//                "AvDsch": "196",
//                        "MaxDsch": "687",
//                        "DschCnt": "1156",
//                        "DschPhase": "258",
//                        "filePrpd": "20190629_100013_511_prpd.png",
//                        "filePrps": "20190629_160616_088_prps.png"
//            }
//        }


    //终端上传采样数据（重症监护协议）
    private void uploadIcuSampleData(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadIcuSampleData");
        try {
            String msgId = obj.getString("msgId");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONArray ComFilearray = contentobj.getJSONArray("ComFile");

            for(int i=0;i<ComFilearray.size();i++) {
                JSONObject ComFileobj = ComFilearray.getJSONObject(i);
                String devSrc=ComFileobj.getString("devSrc");
                String purpose=ComFileobj.getString("purpose");
                String devId=ComFileobj.getString("devId");
                String fileName=ComFileobj.getString("fileName");
                String fileType=ComFileobj.getString("fileType");
                String fileData=ComFileobj.getString("fileData");
                //入库或其他操作
            }
//            String content = obj.getString("msg");
//            logger.debug(result + msg);
            sendJsonResMsgOKorERROR("uploadIcuSampleDataRsp",Constant.CMD_OK,null,obj,null,null,ctx);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }
    }
//        {
//            "action": "uploadIcuSampleData",
//            "msgId":"",
//                "content": {
//            "ComFile": [
//            {
//                "devSrc": "dev",
//                    "purpose": "sampleIcuData",
//                    "devId": "MP01MN1190601000207",
//                    "fileName": "MNT2000_06Mxxxxx_20190414120006651.dat",
//                    "fileType": "dat",
//                    "fileData": "xxxxxxxYYYYzzzzzsssssDDDDcplshaljljajlga"
//            },
//            {
//                "devSrc": "ied",
//                    "purpose": "sampleIcuData",
//                    "devId": "SU10ABC9988765",
//                    "fileName": "MNT2000_06Mxxxxx_20190414120006651.dat",
//                    "fileType": "dat",
//                    "fileData": "xxxxxxxYYYYzzzzzsssssDDDDcplshaljljajlga"
//            }
//]
//        }
//        }

        //应答
//        {
//            "action":"uploadDataRsp",
//                "msgId":"",
//                "result":"ok",
//                "msg":"success"
//        }
//        或者
//        {
//            "action":"uploadDataRsp",
//                "msgId":"",
//                "result":"error",
//                "msg":"文件解析错误"
//        }

    //查询特高频局放底噪
    private void getJfNoiseBaseRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("getJfNoiseBaseRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject JfWarningobj = contentobj.getJSONObject("JfWarning");

            String noiseBase = JfWarningobj.getString("noiseBase");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("getJfNoiseBaseRsp error： " + ex);
        }
//        "result": "ok",
//                "msg": "读取成功",
//                "content": {
//            "JfWarning": {
//                "noiseBase": "210"
//            }
//        }
    }

    //重置特高频局放底噪
    private void setJfNoiseBaseRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("setJfNoiseBaseRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            //入库或其他
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setJfNoiseBaseRsp error： " + ex);
        }
    }

    //查询局放报警参数
    private void getJfWarningRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("getJfWarningRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject JfWarningobj = contentobj.getJSONObject("JfWarning");
            String dischargeCapacityJf = JfWarningobj.getString("dischargeCapacityJf");
            String dischargeFrequencyJf = JfWarningobj.getString("dischargeFrequencyJf");
            String dischargeCapacityDeltaJf = JfWarningobj.getString("dischargeCapacityDeltaJf");
            String dischargeFrequencyDeltaJf = JfWarningobj.getString("dischargeFrequencyDeltaJf");
            String noiseBase = JfWarningobj.getString("noiseBase");

//            noiseBase 特高频局放底噪 int 可选 [-1-1500] -1:重置底噪
//            其他值：直接设置底噪

//            String noiseBase = JfWarningobj.getString("noiseBase");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }
//        "result": "ok",
//                "msg": "读取成功",
//                "content": {
//            "JfWarning": {
//                "dischargeCapacityJf": "1",
//                        "dischargeFrequencyJf": "2000",
//                        "dischargeCapacityDeltaJf": "3000",
//                        "dischargeFrequencyDeltaJf": "2500"
//        noiseBase 特高频局放底噪 int 可选 [-1-1500] -1:重置底噪
//        其他值：直接设置底噪
//            }
//        }
    }

    private void getServerAddressRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("getServerAddressRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("getServerAddressRsp error： " + ex);
        }
    }

    private void setServerAddressRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("setServerAddressRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setServerAddressRsp error： " + ex);
        }
    }

    private void cmdYtRotateRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("cmdYtRotateRsp");
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("cmdYtRotateRsp error： " + ex);
        }
    }

    /**
     *
     * @param q_obj
     * @param obj
     * @param ctx
     *
     * DevConfig 终端信息
     * devSrc 设备来源 String 必备 见附录 附录 devSrc
     *              1 String dev 终端自身
     *              2 String ied IED通道SU10
     *              3 String app 客户端APP
     * devID 设备 ID String 可选 对于 IED 通道设备，需要指定 ID
     * dateTime 时间戳 String 可选 自定义格式 Unix 时间戳，精确到 ms，没有毫秒的把毫秒补零。
     * devState 设备初始化状态 String 可选 见后文
     *          1 init 完成初始化
     *          2 uninit 未初始化
     * allowSampling 是否允许采样 String 必备 见后文 enable/disable
     * cycleRebootTime 重启时间间隔 String 必备 见后文
     *
     * IrOverlay 红外融合功能
     * irOvSupport 红外融合功能支持状态 string 必备 见附录 附录 FeatureSupport
     * IrOvParam 红外融合参数类 Object 可选
     *      IrOvParam 定义
     *      该类定义了红外融合参数值，具体如下：
     *      字段名 含义说明 类型 状态 取值范围 备注
     *      scale 红外图相比背景图放大倍率 float 必备
     *      x 红外图左上角顶点相对背景 x 坐标 float 必备
     *      y 红外图左上角顶点相对背景 y 坐标 float 必备
     *      alpha 红外图透明度 int 必备 [0-255]
     *
     * IrWarning 红外报警监测区域
     * name 区域名称 string 必备 监测
     * type 区域类型 int 必备 [0-2] 监测区域类型，见后文
     *          1 0 线段
     *          2 1 矩形区域
     *          3 2 不规则区域
     * maxTemp 区域允许最高温 int 必备 单位：℃， 超过该温度值终端报警
     * delta 相对温差 δ float 可选 δ = (T1-T2)/(T1-T0) * 100%
     *          T1: 所有区域中 maxTemp 的最大值
     *          T2: 所有区域中 minTemp 的最小值
     *          T0: 环境温度。采用温湿度计的温度值
     * diffTemp 区域内允许最大温差值 int 可选 单位：℃， 区域中最高温和最低温的差值
     * relativeTemp 相对温度值 int 可选 单位：℃， 本例中定义为相间温差值。即各区域最高温的最大差值。
     * distance 区域补偿距离 int 必备 [0-1200] 单位 cm，设置为 0 时不补偿
     * lineWidth 绘制区域时线宽 float 可选 线宽与背景宽度百分比。主要线段类型使用
     * point 监测区域顶点坐标 Object 必备 区域顶点坐标集合
     *      point.x 多边形顶点坐标 x float 必备 x 与背景宽的百分比
     *      point.y 多边形顶点坐标 y float 必备 y 与背景高的百分比
     * criteriaFlag 判据标志位 int 可选 见附录
     *          1 Int 1 SupportMaxTemp,区域最高温判据
     *          2 Int 2 SupportDelta, 相对温差 δ判据
     *          3 Int 4 SupportRelativeTemp，相对温差判据
     *          4 Int 8 SupportDiffTemp, 区域内最大温差值判据
     *
     * ComDevParam 常规参数
     * uploadInterval 采样时间间隔 string 可选 见后文 单位分钟
     *      1 5 5分钟
     *      2 15 15分钟
     *      3 30 30分钟
     *      4 45 45分钟
     *      5 60 60分钟
     *      6 120 120分钟
     * resolutionPhoto 照片分辨率 string 可选 1920*1080
     * resolutionVideo 录像分辨率 string 可选 640*480
     * timeVideo 录像持续时长 string 可选 10 单位： 秒
     * resolutionRVC 视频分辨率 string 可选 640*480
     * timeRVC 视频持续时长 string 可选 1 单位： 分钟
     * precisionTemp 测温精度 string 可选 0.1 精确到小数点后一位
     * resolutionTI 红外热图分辨率 string 可选 640*480 暂未使用
     * epsilonIR 发射率 string 可选 (0-1]
     * distanceIR 补偿距离 string 可选 [0-1200] 单位厘米，为 0 不补偿
     * reflectedTemp 反射温度 string 可选 (0-99) 单位摄氏度
     *
     * JfWarning 局放报警参数
     * dischargeCapacityJf 放电峰值 int 必备 [0-3000] 放电峰值阈值
     * dischargeFrequencyJf 放电频次 int 必备 [0-3000] 放电频次阈值
     * dischargeCapacityDeltaJf 放电峰值 delta int 可选 [0-3000]
     * dischargeFrequencyDeltaJf 放电频次 delta int 可选 [0-3000]
     * noiseBase 特高频局放底噪 int 可选 [-1-1500] -1:重置底噪其他值：直接设置底噪
     *
     * CameraWarning 可见光报警参数
     * camIDSupport 异物入侵检测开启状态 String 必备 见附录 见后文 enable、disable
     * idSerial 异物入侵百度序列号 String 可选 见后文
     */
    private void uploadDevAttr(JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        logger.debug("uploadDevAttr");
        try {
            boolean saveflag;
            String msgId = obj.getString("msgId");
            JSONObject contentobj = obj.getJSONObject("content");
            if(contentobj != null) {
                JSONObject DevConfigobj = contentobj.getJSONObject("DevConfig");
                if (DevConfigobj != null) {
                    String devSrc = DevConfigobj.getString("devSrc");
                    String devId = DevConfigobj.getString("devId");
                    String dateTime = DevConfigobj.getString("dateTime");
                    String devState = DevConfigobj.getString("devState");
                    String allowSampling = DevConfigobj.getString("allowSampling");
                    String cycleRebootTime = DevConfigobj.getString("cycleRebootTime");

                    TInfoDevInfoEntity tInfoDevInfoEntity = new TInfoDevInfoEntity();
                    tInfoDevInfoEntity.setDevCode(devId);
                    tInfoDevInfoEntity.setIpAddr(obj.getString("从站地址"));
                    List<TInfoDevInfoEntity> list = serverHandler.tInfoDevInfoService.queryDevListByCondition(tInfoDevInfoEntity);
                    if(list != null) {
                        for(int i=0;i < list.size();i++) {
                            tInfoDevInfoEntity = list.get(i);
                            serverHandler.tInfoDevInfoService.updateById(tInfoDevInfoEntity);
                            logger.debug("updateById tInfoDevInfoEntity");
                        }
                    } else {
                        tInfoDevInfoEntity.setCreateOpr((long)0);
                        tInfoDevInfoEntity.setCreateTime(new Date());
                        tInfoDevInfoEntity.setLastOpr((long)0);
                        tInfoDevInfoEntity.setLastTime(new Date());
                        saveflag = serverHandler.tInfoDevInfoService.save(tInfoDevInfoEntity);
                        if(!saveflag){
                            logger.error("保存数据库失败 uploadDevAttrRsp tInfoDevInfoEntity");
                            sendJsonResMsgOKorERROR("uploadDevAttrRsp",Constant.CMD_ERROR,null,obj,null,null,ctx);
                            return;
                        }
                    }
                }

                JSONObject IrOverlayobj = contentobj.getJSONObject("IrOverlay");
                if (IrOverlayobj != null) {
                    String irOvSupport = IrOverlayobj.getString("irOvSupport");
                    JSONObject IrOvParamobj = IrOverlayobj.getJSONObject("IrOvParam");
                    if (IrOvParamobj != null) {
                        String scale = IrOvParamobj.getString("scale");
                        String x = IrOvParamobj.getString("x");
                        String y = IrOvParamobj.getString("y");
                        String alpha = IrOvParamobj.getString("alpha");
                    }
                }

                JSONArray IrWarningarray = contentobj.getJSONArray("IrWarning");
                if (IrWarningarray != null) {
                    for (int i = 0; i < IrWarningarray.size(); i++) {
                        JSONObject IrWarningobj = IrWarningarray.getJSONObject(i);
                        String delta = IrWarningobj.getString("delta");
                        String diffTemp = IrWarningobj.getString("diffTemp");
                        String distance = IrWarningobj.getString("distance");
                        String lineWidth = IrWarningobj.getString("lineWidth");
                        String maxTemp = IrWarningobj.getString("maxTemp");
                        String name = IrWarningobj.getString("name");
                        String relativeTemp = IrWarningobj.getString("relativeTemp");
                        String type = IrWarningobj.getString("type");
                        String criteriaFlag = IrWarningobj.getString("criteriaFlag");
                        JSONArray pointarray = contentobj.getJSONArray("point");
                        if (pointarray != null) {
                            for (int j = 0; j < IrWarningarray.size(); j++) {
                                JSONObject pointobj = IrWarningarray.getJSONObject(j);
                                String x = pointobj.getString("x");
                                String y = pointobj.getString("y");
                            }
                        }
                    }
                }

                JSONObject ComDevParamobj = contentobj.getJSONObject("ComDevParam");
                if (ComDevParamobj != null) {
                    String uploadInterval = ComDevParamobj.getString("uploadInterval");
                    String resolutionPhoto = ComDevParamobj.getString("resolutionPhoto");
                    String resolutionVideo = ComDevParamobj.getString("resolutionVideo");
                    String timeVideo = ComDevParamobj.getString("timeVideo");
                    String resolutionRVC = ComDevParamobj.getString("resolutionRVC");
                    String timeRVC = ComDevParamobj.getString("timeRVC");
                    String precisionTemp = ComDevParamobj.getString("precisionTemp");
                    String resolutionTI = ComDevParamobj.getString("resolutionTI");
                    String epsilonIR = ComDevParamobj.getString("epsilonIR");
                    String distanceIR = ComDevParamobj.getString("distanceIR");
                    String reflectedTemp = ComDevParamobj.getString("reflectedTemp");
                }

                JSONObject JfWarningobj = contentobj.getJSONObject("JfWarning");
                if (JfWarningobj != null) {
                    String dischargeCapacityJf = JfWarningobj.getString("dischargeCapacityJf");
                    String dischargeFrequencyJf = JfWarningobj.getString("dischargeFrequencyJf");
                    String dischargeCapacityDeltaJf = JfWarningobj.getString("dischargeCapacityDeltaJf");
                    String dischargeFrequencyDeltaJf = JfWarningobj.getString("dischargeFrequencyDeltaJf");
                }

                JSONObject CameraWarningobj = contentobj.getJSONObject("CameraWarning");
                if (CameraWarningobj != null) {
                    String camIDSupport = CameraWarningobj.getString("camIDSupport");
                }

                JSONObject IedSubDevAttrobj = contentobj.getJSONObject("IedSubDevAttr");
                if (IedSubDevAttrobj != null) {
                    String devSrc = IedSubDevAttrobj.getString("devSrc");
                    String devId = IedSubDevAttrobj.getString("devId");
                    String macAddr = IedSubDevAttrobj.getString("macAddr");
                    String sampleBand = IedSubDevAttrobj.getString("sampleBand");
                    String sampleFreq = IedSubDevAttrobj.getString("sampleFreq");
                    String listenInterval = IedSubDevAttrobj.getString("listenInterval");
                    String sampleStartTime = IedSubDevAttrobj.getString("sampleStartTime");
                    String sampleInterval = IedSubDevAttrobj.getString("sampleInterval");
                    String sampleDurationTime = IedSubDevAttrobj.getString("sampleDurationTime");
                }
            }


            sendJsonResMsgOKorERROR("uploadDevAttrRsp",Constant.CMD_OK,null,q_obj,null,null,ctx);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }

//        "action": "uploadDevAttr",
//                "content": {
//            "IedSubDevAttr": {
//                "devSrc": "ied",
//                        "devId": "SU10ABC123456",
//                        "macAddr": "36,45,12,ac",
//                        "sampleBand": "2",
//                        "sampleFreq": "1",
//                        "listenInterval": "15,25",
//                        "sampleStartTime": "12,30,30",
//                "sampleInterval": "5,36",
//                        "sampleDurationTime": "50"
//            }
//        }

//        "action": "uploadDevAttr",
//                "content": {
//            "DevConfig": {
//                "devSrc": "dev",
//                        "devId": "TP01MN2181221000042",
//                        "dateTime": "1514707265557",
//                        "devState": "init",
//                        "allowSampling": "enable",
//                        "cycleRebootTime": "24"
//            },
//            "IrOverlay": {
//                "irOvSupport": "enable",
//                        "IrOvParam": {
//                    "scale": 1.8156897,
//                            "x": 0.099213384,
//                            "y": -0.06233221,
//                            "alpha": 170
//                }
//            },
//            "IrWarning": [
//            {
//                "delta": 0.95,
//                    "diffTemp": 200,
//                    "distance": 200,
//                    "lineWidth": 0.013333,
//                    "maxTemp": 85,
//                    "name": "C",
//                    "point": [
//                {
//                    "x": 0.33571428,
//                        "y": 0.30114287
//                },
//                {
//                    "x": 0.62,
//                        "y": 0.30114287
//                },
//                {
//                    "x": 0.62,
//                        "y": 0.812
//                },
//                {
//                    "x": 0.33571428,
//                        "y": 0.812
//                }
//],
//                "relativeTemp": 0,
//                    "type": 1,
//                    "criteriaFlag": 12
//            },
//            {
//                "delta": 0.95,
//                    "diffTemp": 200,
//                    "distance": 200,
//                    "lineWidth": 0.013333,
//                    "maxTemp": 85,
//                    "name": "A",
//                    "point": [
//                {
//                    "x": 0.105714284,
//                        "y": 0.164
//                },
//                {
//                    "x": 0.3548796,
//                        "y": 0.164
//                },
//                {
//                    "x": 0.3548796,
//                        "y": 0.9874735
//                },
//                {
//                    "x": 0.105714284,
//                        "y": 0.9874735
//                }
//],
//                "relativeTemp": 0,
//                    "type": 1,
//                    "criteriaFlag": 12
//            }
//],
//            "ComDevParam": {
//                "uploadInterval": "15",
//                        "resolutionPhoto": "1920*1080",
//                        "resolutionVideo": "640*480",
//                "timeVideo": "10",
//                        "resolutionRVC": "640*480",
//                        "timeRVC": "1",
//                        "precisionTemp": "0.1",
//                        "resolutionTI": "640*480",
//                        "epsilonIR": "0.97",
//                        "distanceIR": "300",
//                        "reflectedTemp": "28"
//            },
//            "JfWarning": {
//                "dischargeCapacityJf": "1",
//                        "dischargeFrequencyJf": "2000",
//                        "dischargeCapacityDeltaJf": "3000",
//                        "dischargeFrequencyDeltaJf": "2500"
//            },
//            "CameraWarning": {
//                "camIDSupport": "enable"
//            }
//        }
    }

    private void setIedSubDevParamRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("成功");
            result.equals("error");
            msg.equals("失败");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }
    }

    private void cmdRtSamplingModRsp(JSONObject obj, ChannelHandlerContext ctx) {
    }

    private void getIedNodeInfoRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("success");
            result.equals("error");
            msg.equals("设备忙，失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONArray IedNodeInfoarray = contentobj.getJSONArray("IedNodeInfo");
            for(int i=0;i<IedNodeInfoarray.size();i++) {
                JSONObject IedNodeInfoobj = IedNodeInfoarray.getJSONObject(i);
                String devSrc = IedNodeInfoobj.getString("devSrc");
                String devId = IedNodeInfoobj.getString("devId");
                String devProduct = IedNodeInfoobj.getString("devProduct");
                String devType = IedNodeInfoobj.getString("devType");
                String macAddr = IedNodeInfoobj.getString("macAddr");
                String onLineState = IedNodeInfoobj.getString("onLineState");
                String batteryLevel = IedNodeInfoobj.getString("batteryLevel");
                String devState = IedNodeInfoobj.getString("devState");
                //入库或更新操作
            }

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }
//        "action": "getIedNodeInfoRsp",
//                "result":"ok",
//                "msg":"success",
//                "content": {
//            "IedNodeInfo": [
//            {
//                "devSrc": "ied",
//                    "devId": "SU10ABC123456",
//                    "devProduct": "SU10",
//                    "devType": "",
//                    "macAddr": "",
//                    "onLineState": "online",
//                    "batteryLevel": "230",
//                    "devState": "uninit"
//            },
//            {
//                "devSrc": "ied",
//                    "devId": "SU10ABC665588",
//                    "devProduct": "SU10",
//                    "devType": "",
//                    "macAddr": "",
//                    "onLineState": "offline",
//                    "batteryLevel": "200",
//                    "devState": "init"
//            },
//            {
//                "devSrc": "ied",
//                    "devId": "SU10ABC997711",
//                    "devProduct": "SU10",
//                "devType": "",
//                    "macAddr": "",
//                    "onLineState": "online",
//                    "batteryLevel": "150",
//                    "devState": "init"
//            }
//]
//        }
    }

    //终端上传局放实时视频数据
    private void uploadJfStream(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
//            String result = obj.getString("result");
            String msgId = obj.getString("msgId");
//
//            result.equals("ok");
//            msg.equals("成功");
//            result.equals("error");
//            msg.equals("设备忙，失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject JfVideoStreamDataobj = contentobj.getJSONObject("JfVideoStreamData");

            String devSrc = JfVideoStreamDataobj.getString("devSrc");
            String purpose = JfVideoStreamDataobj.getString("purpose");
            String devId = JfVideoStreamDataobj.getString("devId");
            String arrayType = JfVideoStreamDataobj.getString("arrayType");
            String ePhase = JfVideoStreamDataobj.getString("ePhase");
            String eFreq = JfVideoStreamDataobj.getString("eFreq");
            String array = JfVideoStreamDataobj.getString("array");
            //入库或更新操作

            sendJsonResMsgOKorERROR("uploadJfStreamRsp",Constant.CMD_OK,null,obj,null,null,ctx);
//            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }
//        "action": "uploadJfStream",
//                "msgId":"",
//                "content": {
//            "JfVideoStreamData": {
//                "devSrc": "dev",
//                        "purpose": "jfVideoStream",
//                        "devId": "TP01MN2181221000042",
//                        "arrayType": "double",
//                        "ePhase": "60",
//                        "eFreq": "50",
//                        "array": "123.1,23.1,78.0,109.7,xxx,145.0"
//            }
//        }
    }

    //获取终端数据
    private void getDevDataRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("成功");
            result.equals("error");
            msg.equals("设备忙，失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONArray ComDataarray = contentobj.getJSONArray("ComData");
            for(int i=0;i<ComDataarray.size();i++) {
                JSONObject ComDataobj = ComDataarray.getJSONObject(i);
                String devSrc = ComDataobj.getString("devSrc");
                String purpose = ComDataobj.getString("purpose");
                String devId = ComDataobj.getString("devId");
                //入库或更新操作
            }

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }
//        "action": "getDevData",
//                "msgId":"",
//                "content": {
//            "ComData": [
//            {
//                "devSrc": "dev",
//                    "purpose": "jfPrpd",
//                    "devId": "TP01MN2181221000042"
//            },
//            {
//                "devSrc": "dev",电力设备在线监测通信协议
//                34 / 73
//                "purpose": "jfPrps",
//                    "devId": "TP01MN2181221000042"
//            }
//]
//        }
    }

    //通用上传文件
    private void uploadFile(JSONObject q_obj,JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
//            String result = obj.getString("result");
//            String msg = obj.getString("msg");
            String msgId = obj.getString("msgId");

//            result.equals("ok");
//            msg.equals("成功");
//            result.equals("error");
//            msg.equals("设备忙，失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONArray ComFilearray = contentobj.getJSONArray("ComFile");
            for(int i=0;i<ComFilearray.size();i++) {
                JSONObject ComFileobj = ComFilearray.getJSONObject(i);
                String devSrc = ComFileobj.getString("devSrc");
                String purpose = ComFileobj.getString("purpose");
                String devId = ComFileobj.getString("devId");
                String fileName = ComFileobj.getString("fileName");
                String fileType = ComFileobj.getString("fileType");
                String fileData = ComFileobj.getString("fileData");
                //入库或更新操作
                boolean saveflag;
                int upsum = 0;
                if(purpose.equals("log")) {
                    TFileLogInfoEntity tFileLogInfoEntity = new TFileLogInfoEntity();
                    tFileLogInfoEntity.setDevId(devId);
                    tFileLogInfoEntity.setDevSrc(devSrc);
                    tFileLogInfoEntity.setPurpose(purpose);
                    tFileLogInfoEntity.setFileName(fileName);
                    tFileLogInfoEntity.setFileType(fileType);
                    tFileLogInfoEntity.setFileData(fileData);
                    tFileLogInfoEntity.setCreateOpr((long)0);
                    tFileLogInfoEntity.setLastOpr((long)0);
                    tFileLogInfoEntity.setCreateTime(new Date());
                    tFileLogInfoEntity.setLastTime(new Date());
                    saveflag = serverHandler.tFileLogInfoService.save(tFileLogInfoEntity);
                    if(!saveflag){
                        logger.error("保存数据库失败 uploadFileRsp tFileLogInfoEntity");
                        sendJsonResMsgOKorERROR("uploadFileRsp",Constant.CMD_ERROR,null,q_obj,null,null,ctx);
                        return;
                    }

                }else {
                    TFileInfoEntity tFileInfoEntity = new TFileInfoEntity();
                    tFileInfoEntity.setDevId(devId);
                    tFileInfoEntity.setDevSrc(devSrc);
                    tFileInfoEntity.setPurpose(purpose);
                    tFileInfoEntity.setFileName(fileName);
                    tFileInfoEntity.setFileType(fileType);
                    tFileInfoEntity.setFileData(fileData);
                    tFileInfoEntity.setCreateOpr((long)0);
                    tFileInfoEntity.setLastOpr((long)0);
                    tFileInfoEntity.setCreateTime(new Date());
                    tFileInfoEntity.setLastTime(new Date());
                    upsum = serverHandler.tFileInfoService.updateFileValueByDevData(tFileInfoEntity);
                    logger.debug("updateByDevId(tFileInfoEntity)更新数据库影响数目：" + upsum);
                    if(upsum <= 0) {
                        logger.debug("插入新数据 ：" + devId);
                        saveflag = serverHandler.tFileInfoService.save(tFileInfoEntity);
                        if (!saveflag) {
                            logger.error("保存数据库失败 uploadFileRsp tFileInfoEntity");
                            sendJsonResMsgOKorERROR("uploadFileRsp", Constant.CMD_ERROR, null, q_obj, null, null, ctx);
                            return;
                        }
                    }

                    // 插入历史表
                    TFileInfoHisEntity tFileInfoHisEntity = new TFileInfoHisEntity();
                    tFileInfoHisEntity.setDevId(devId);
                    tFileInfoHisEntity.setDevSrc(devSrc);
                    tFileInfoHisEntity.setPurpose(purpose);
                    tFileInfoHisEntity.setFileName(fileName);
                    tFileInfoHisEntity.setFileType(fileType);
                    tFileInfoHisEntity.setFileData(fileData);
                    tFileInfoHisEntity.setCreateOpr((long)0);
                    tFileInfoHisEntity.setLastOpr((long)0);
                    tFileInfoHisEntity.setCreateTime(new Date());
                    tFileInfoHisEntity.setLastTime(new Date());
                    tFileInfoHisService.add(tFileInfoHisEntity);
                }
            }

            sendJsonResMsgOKorERROR("uploadFileRsp",Constant.CMD_OK,null,q_obj,null,null,ctx);

//            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("uploadFile error： " + ex);
        }
//        "action": "uploadFile",
//                "msgId":"",
//                "content": {
//            "ComFile": [
//            {
//                "devSrc": "dev",
//                    "purpose": "log",
//                    "devId": "",
//                    "fileName": "20190716-155851.zip",
//                    "fileType": "zip",
//                    "fileData": "xxxxxxxYYYYzzzzzsssssDDDDcplshaljljajlga"
//            }
//]
//        }

        //应答
//        {
//            "action":"uploadFileRsp",
//                "msgId":"",
//                "result":"ok",
//                "msg":"success"
//        }
    }

    //通知终端上传局放 PRPD 和 PRPS 图谱 /通知终端上传红外热图/通知终端上传 SU10 数据
    private void getDevFileRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("成功");
            result.equals("error");
            msg.equals("设备忙，失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONArray ComFilearray = contentobj.getJSONArray("ComFile");
            for(int i=0;i<ComFilearray.size();i++) {
                JSONObject ComFileobj = ComFilearray.getJSONObject(i);
                String devSrc = ComFileobj.getString("devSrc");
                String purpose = ComFileobj.getString("purpose");
                String devId = ComFileobj.getString("devId");
                //入库或更新操作
            }

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }
//        {
//            "action": "getDevFile",
//                "msgId":"",
//                "content": {
//            "ComFile": [
//            {
//                "devSrc": "dev",
//                    "purpose": "irImg",
//                    "devId": "TP01MN2181221000042"
//            }
//]
//        }
//        }
    }

    //控制设备延时重启
    private void cmdDevRebootRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("成功");
            result.equals("error");
            msg.equals("设备忙，失败");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }

    }

    //控制终端热点
    private void cmdWiFiHotSpotsRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("热点正在开启");
            result.equals("error");
            msg.equals("设备忙，无法召测");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }
    }

    //控制终端实时视频
    private void cmdVideoStreamRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("开始召测");
            msg.equals("召测成功");
            result.equals("error");
            msg.equals("设备忙，无法召测");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("cmdVideoStreamRsp error： " + ex);
        }
    }

    //坏点修复
    private void cmdIrBPRRsp(JSONObject obj, ChannelHandlerContext ctx) {
        //坏点修复是一个异步动作，此处需要先正常响应（可执行或者不能执行）。红外模组
        //修复结束后终端上传修复结果（待定），上传协议见后文。
    }

    //召测
    private void cmdRtSamplingRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

//            result.equals("ok");
//            msg.equals("开始召测");
//            msg.equals("召测成功");
//            result.equals("error");
//            msg.equals("设备忙，无法召测");
            //入库或更新操作
            logger.debug("召测 入库或更新操作：" + result + msg);
        }catch(Exception ex) {
            logger.error("cmdRtSamplingRsp error： " + ex);
        }
//        "action": "cmdRtSamplingRsp",
//                "msgId":"",
//                "result": "error",
//                "msg": "设备忙，无法召测"
//    }
//    或者
//    {
//        "action": "cmdRtSamplingRsp",
//            "msgId":"",
//            "result": "ok",
//            "msg": "开始召测"
//    }
//    或者
//    {
//        "action": "cmdRtSamplingRsp",
//            "msgId":"",
//            "result": "ok",
//            "msg": "召测成功"
//    }
    }

    //读取传感器信息
    private void getSensorInfoRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONArray SensorInfoarray = contentobj.getJSONArray("SensorInfo");
            for(int i=0;i<SensorInfoarray.size();i++){
                JSONObject SensorInfoobj = SensorInfoarray.getJSONObject(i);
                String module = SensorInfoobj.getString("module");
                String deviceId = SensorInfoobj.getString("deviceId");
                String manufacturer = SensorInfoobj.getString("manufacturer");
                String pixelSize = SensorInfoobj.getString("pixelSize");
                //入库或更新操作
            }

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setNetConfigRsp error： " + ex);
        }
//        "result": "ok",
//                "msg": "读取成功",
//                "content": {
//            "SensorInfo": [
//            {
//                "module": "IR",
//                    "model": "",
//                    "deviceId": "251420193",
//                    "manufacturer": "thermapp",
//                    "pixelSize": "0.11M"
//            },
//            {
//                "module": "Camera",
//                    "model": "",
//                    "deviceId": "251420193",
//                    "manufacturer": "智汇",
//                    "pixelSize": "4M"
//            },
//            {
//                "module": "UHF",
//                    "model": "",
//                    "deviceId": "",
//                    "manufacturer": "迈内",
//                    "pixelSize": ""
//            }
//]}
    }

    //抓取终端 log
    private void getDevLogRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setNetConfigRsp error： " + ex);
        }
//        {
//            "action": "uploadDevLog",
//                "content": {
//            "DevLog": {
//                "fileLog": "20190629_100013_511.zip"
//            }
//        }
//        }
    }

    //设置终端组网配置参数
    private void setNetConfigRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setNetConfigRsp error： " + ex);
        }
    }

    //设置操作人
    private void setOperateRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setOperateRsp error： " + ex);
        }
    }

    //查询台账信息
    private void getStandingBookRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject StandingBookobj = contentobj.getJSONObject("StandingBook");
            String devSrc = StandingBookobj.getString("devSrc");
            String devId = StandingBookobj.getString("devId");
            String sbType = StandingBookobj.getString("sbType");

            JSONArray SbInfoarray = StandingBookobj.getJSONArray("SbInfo");
            for(int i=0;i<SbInfoarray.size();i++){
                JSONObject SbInfoobj = SbInfoarray.getJSONObject(i);
                String sbName = SbInfoobj.getString("sbName");
                String stationName = SbInfoobj.getString("stationName");
                String stationCode = SbInfoobj.getString("stationCode");
                String dutName = SbInfoobj.getString("dutName");
                String dutCode = SbInfoobj.getString("dutCode");
                String tsName = SbInfoobj.getString("tsName");
                String tsCode = SbInfoobj.getString("tsCode");
                //入库或更新操作
            }

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setCamWarningRsp error： " + ex);
        }
//        "result": "ok",
//                "msg": "读取成功",
//                "content": {
//            "StandingBook": {
//                "devSrc": "dev",
//                        "devId": "MP01MN1190601000207",
//                        "sbType": "3",
//                        "SbInfo": [
//                {
//                    "sbName": "SU100001",
//                        "stationName": "220kV团岛变电站",
//                        "stationCode": "06M00000000106294_zf01",
//                        "dutName": "1号220kV主变",
//                        "dutCode": "06M00000000106640_0301",
//                        "tsName": "1号主变低压侧",
//                        "tsCode": "06M00000000106640_0301_002"
//                },
//                {
//                    "sbName": "SU100002",
//                        "stationName": "220kV团岛变电站",
//                        "stationCode": "06M00000000106294_zf01",
//                        "dutName": "1号220kV主变",
//                        "dutCode": "06M00000000106640_0301",
//                        "tsName": "1号主变低压侧",
//                        "tsCode": "06M00000000106640_0301_001"
//                }
//]
//            }
//        }
    }

    //配置台账信息
    private void setStandingBookRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setCamWarningRsp error： " + ex);
        }
    }

    //查询 IP 地址信息
    private void getDevIPRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject IPInfoobj = contentobj.getJSONObject("IPInfo");
            String ipVersion = IPInfoobj.getString("ipVersion");
            String ipType = IPInfoobj.getString("ipType");
            String ipAddres = IPInfoobj.getString("ipAddres");
            String mask = IPInfoobj.getString("mask");
            String gateway = IPInfoobj.getString("gateway");
            String dns = IPInfoobj.getString("dns");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setCamWarningRsp error： " + ex);
        }
//        "result": "ok",
//                "msg": "读取成功",
//                "content": {
//            "IPInfo": {
//                "ipVersion": "IPv4",
//                        "ipType": "static",
//                        "ipAddres": "192.168.0.168",
//                        "mask": "255.255.255.0",
//                        "gateway": "192.168.0.254",
//                        "dns": "202.96.209.133"
//            }
//        }
    }

    //设置终端 IP 地址
    private void setDevIPRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setCamWarningRsp error： " + ex);
        }
    }

    //查询可见光报警参数
    private void getCamWarningRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");
            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject CameraWarningobj = contentobj.getJSONObject("CameraWarning");
            String camIDSupport = CameraWarningobj.getString("CameraWarningobj");
            String idSerial = CameraWarningobj.getString("idSerial");
            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setCamWarningRsp error： " + ex);
        }
//        "content": {
//            "CameraWarning": {
//                "camIDSupport": "enable",
//                        "idSerial": "123ABCSN098877"
//            }
//        }
    }

    //设置可见光报警参数
    private void setCamWarningRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");

            //入库或更新操作
            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setCamWarningRsp error： " + ex);
        }
    }

    //设置局放报警参数
    private void setJfWarningRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }
    }

    //查询终端常规参数
    private void getDevParamRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("读取成功");
            result.equals("error");
            msg.equals("读取失败");

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject ComDevParamobj = contentobj.getJSONObject("ComDevParam");
            String uploadInterval = ComDevParamobj.getString("uploadInterval");
            String resolutionPhoto = ComDevParamobj.getString("resolutionPhoto");
            String resolutionVideo = ComDevParamobj.getString("resolutionVideo");
            String timeVideo = ComDevParamobj.getString("timeVideo");
            String resolutionRVC = ComDevParamobj.getString("resolutionRVC");
            String timeRVC = ComDevParamobj.getString("timeRVC");
            String precisionTemp = ComDevParamobj.getString("precisionTemp");
            String resolutionTI = ComDevParamobj.getString("resolutionTI");
            String epsilonIR = ComDevParamobj.getString("epsilonIR");
            String distanceIR = ComDevParamobj.getString("distanceIR");
            String reflectedTemp = ComDevParamobj.getString("reflectedTemp");
            //入库或更新操作

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }
//        "action": "rsp",
//                "msgId":"",
//                "result": "ok",
//                "msg": "读取成功",
//                "content":{
//            "ComDevParam":{
//                "uploadInterval":"15",
//                        "resolutionPhoto":"1920*1080",
//                        "resolutionVideo":"640*480",
//                        "timeVideo":"10",
//                        "resolutionRVC":"640*480",
//                        "timeRVC":"1",
//                        "precisionTemp":"0.1",
//                        "resolutionTI":"640*480",
//                        "epsilonIR":"0.97",
//                        "distanceIR":"300",
//                        "reflectedTemp":"28"
//            }
//        }
    }

    //设置终端常规参数
    private void setDevParamRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }
    }

    //设置红外报警（监测区域）参数
    private void setIrWarningRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }
    }

    //设置红外融合参数
    private void setIrOverlayRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }
    }

    //获取终端信息
    private void getDevInfoRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            JSONObject contentobj = obj.getJSONObject("content");
            JSONObject DevInfoobj = contentobj.getJSONObject("DevInfo");
            String devId = DevInfoobj.getString("devId");
            String version = DevInfoobj.getString("version");
            String irModType = DevInfoobj.getString("irModType");
            String dateTime = DevInfoobj.getString("dateTime");
            String devState = DevInfoobj.getString("devState");
            String allowSampling = DevInfoobj.getString("allowSampling");
            String cycleRebootTime = DevInfoobj.getString("cycleRebootTime");
            //入库或更新操作

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }
//        "action": "getDevInfoRsp",
//                "msgId":"",
//                "result": "ok",
//        "msg": "读取成功",
//        "content": {
//            "DevInfo": {
//                "devId": "MP01MN1190601000238",
//                        "version": "T2000__CH_U_V190715BCF2FF21",
//                        "irModType": "heiman",
//                        "dateTime": "1514707265557",
//                        "devState": "init",
//                        "allowSampling": "enable",
//                        "cycleRebootTime": "24"
//            }
//        }
//        devSrc 设备来源 String 必备 见附录 附录 devSrc
//        devID 设备 ID String 可选 对于 IED 通道设备，需要指定 ID
//        dateTime 时间戳 String 可选 自定义格式 Unix 时间戳，精确到 ms，没有毫秒的
//        把毫秒补零。
//        devState 设备初始化状态 String 可选 见后文
//        allowSampling 是否允许采样 String 必备 见后文 FeatureSupport 定义
//        cycleRebootTime 重启时间间隔 String 必备 见后文
    }

    //设置循环重启时间
    private void setCycleRebootTimeRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setCycleRebootTimeRsp error： " + ex);
        }
    }

    //设置终端权限
    private void setDevPermissionRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }
    }

    //修改终端状态响应
    private void setDevStateRsp(JSONObject obj, ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }
    }

    //授时响应
    private void setDevDataRsp(JSONObject obj,ChannelHandlerContext ctx) {
//        logger.debug("消息json:" + obj);
        try {
            String result = obj.getString("result");
            String msg = obj.getString("msg");

            result.equals("ok");
            msg.equals("授时成功");
            result.equals("error");
            msg.equals("授时失败");
            //入库或页面提示

            logger.debug(result + msg);
        }catch(Exception ex) {
            logger.error("setDevDataRsp error： " + ex);
        }
    }


    /**
     * 将base64转成图片
     *
     * @param fileBase64String base64
     * @param filePath 要保存的文件路径
     */
    public static void convertBase64ToFile(String fileBase64String, String filePath) {
        BufferedOutputStream bos = null;
        FileOutputStream fos = null;
        File file = null;
        try {
            File dir = new File(filePath);
            if (!dir.exists() && dir.isDirectory()) {//判断文件目录是否存在
                dir.mkdirs();
            }

            Base64.Decoder decoder = Base64.getDecoder();
            byte[] bfile = decoder.decode(fileBase64String);

            file = new File(filePath);
            fos = new FileOutputStream(file);
            bos = new BufferedOutputStream(fos);
            bos.write(bfile);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (bos != null) {
                try {
                    bos.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
}